ref: 5e10951c476f6af1eda5ae253805b51f0b257050
parent: af6feaa45c4a865f91eb8c1b049e51dffa2e7456
author: Martin Storsjö <[email protected]>
date: Tue Jan 21 07:07:16 EST 2014
Use sysctl instead of the deprecated Gestalt API for getting the number of cores on OS X Also use the __APPLE__ predefined define instead of MACOS for enabling these code paths. This also avoids having to link to the CoreServices framework in order to get the Gestalt function.
--- a/codec/common/WelsThreadLib.cpp
+++ b/codec/common/WelsThreadLib.cpp
@@ -182,10 +182,11 @@
#elif defined(__GNUC__)
-#ifdef MACOS
-#include <CoreServices/CoreServices.h>
-//#include <Gestalt.h>
-#endif//MACOS
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#include <sys/param.h>
+#include <unistd.h>
+#endif//__APPLE__
void WelsSleep (uint32_t dwMilliseconds) {
usleep (dwMilliseconds * 1000); // microseconds
@@ -306,7 +307,7 @@
if (dwMilliseconds != (uint32_t) - 1) {
return sem_wait (event);
} else {
-#if defined(MACOS)
+#if defined(__APPLE__)
int32_t err = 0;
int32_t wait_count = 0;
do {
@@ -329,7 +330,7 @@
ts.tv_nsec = tv.tv_usec * 1000 + (dwMilliseconds % 1000) * 1000000;
return sem_timedwait (event, &ts);
-#endif//MACOS
+#endif//__APPLE__
}
}
@@ -348,7 +349,7 @@
nIdx = 0; // access each event by order
while (nIdx < nCount) {
int32_t err = 0;
-//#if defined(MACOS) // clock_gettime(CLOCK_REALTIME) & sem_timedwait not supported on mac, so have below impl
+//#if defined(__APPLE__) // clock_gettime(CLOCK_REALTIME) & sem_timedwait not supported on mac, so have below impl
int32_t wait_count = 0;
// struct timespec ts;
// struct timeval tv;
@@ -462,10 +463,10 @@
#else
- SInt32 cpunumber;
- Gestalt (gestaltCountOfCPUs, &cpunumber);
+ size_t len = sizeof (pInfo->ProcessorCount);
- pInfo->ProcessorCount = cpunumber;
+ if (sysctlbyname ("hw.logicalcpu", &pInfo->ProcessorCount, &len, NULL, 0) == -1)
+ pInfo->ProcessorCount = 1;
return WELS_THREAD_ERROR_OK;