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.
This commit is contained in:
Martin Storsjö 2014-01-21 12:07:16 +02:00
parent af6feaa45c
commit 5e10951c47

View File

@ -182,10 +182,11 @@ WELS_THREAD_ERROR_CODE WelsQueryLogicalProcessInfo (WelsLogicalProcessInfo* p
#elif defined(__GNUC__) #elif defined(__GNUC__)
#ifdef MACOS #ifdef __APPLE__
#include <CoreServices/CoreServices.h> #include <sys/sysctl.h>
//#include <Gestalt.h> #include <sys/param.h>
#endif//MACOS #include <unistd.h>
#endif//__APPLE__
void WelsSleep (uint32_t dwMilliseconds) { void WelsSleep (uint32_t dwMilliseconds) {
usleep (dwMilliseconds * 1000); // microseconds usleep (dwMilliseconds * 1000); // microseconds
@ -306,7 +307,7 @@ WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t
if (dwMilliseconds != (uint32_t) - 1) { if (dwMilliseconds != (uint32_t) - 1) {
return sem_wait (event); return sem_wait (event);
} else { } else {
#if defined(MACOS) #if defined(__APPLE__)
int32_t err = 0; int32_t err = 0;
int32_t wait_count = 0; int32_t wait_count = 0;
do { do {
@ -329,7 +330,7 @@ WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t
ts.tv_nsec = tv.tv_usec * 1000 + (dwMilliseconds % 1000) * 1000000; ts.tv_nsec = tv.tv_usec * 1000 + (dwMilliseconds % 1000) * 1000000;
return sem_timedwait (event, &ts); return sem_timedwait (event, &ts);
#endif//MACOS #endif//__APPLE__
} }
} }
@ -348,7 +349,7 @@ WELS_THREAD_ERROR_CODE WelsMultipleEventsWaitSingleBlocking (uint32_t nCount,
nIdx = 0; // access each event by order nIdx = 0; // access each event by order
while (nIdx < nCount) { while (nIdx < nCount) {
int32_t err = 0; 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; int32_t wait_count = 0;
// struct timespec ts; // struct timespec ts;
// struct timeval tv; // struct timeval tv;
@ -462,10 +463,10 @@ WELS_THREAD_ERROR_CODE WelsQueryLogicalProcessInfo (WelsLogicalProcessInfo* p
#else #else
SInt32 cpunumber; size_t len = sizeof (pInfo->ProcessorCount);
Gestalt (gestaltCountOfCPUs, &cpunumber);
pInfo->ProcessorCount = cpunumber; if (sysctlbyname ("hw.logicalcpu", &pInfo->ProcessorCount, &len, NULL, 0) == -1)
pInfo->ProcessorCount = 1;
return WELS_THREAD_ERROR_OK; return WELS_THREAD_ERROR_OK;