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:
parent
af6feaa45c
commit
5e10951c47
@ -182,10 +182,11 @@ WELS_THREAD_ERROR_CODE WelsQueryLogicalProcessInfo (WelsLogicalProcessInfo* p
|
||||
|
||||
#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 @@ WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t
|
||||
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 @@ WELS_THREAD_ERROR_CODE WelsEventWaitWithTimeOut (WELS_EVENT* event, uint32_t
|
||||
ts.tv_nsec = tv.tv_usec * 1000 + (dwMilliseconds % 1000) * 1000000;
|
||||
|
||||
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
|
||||
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 @@ WELS_THREAD_ERROR_CODE WelsQueryLogicalProcessInfo (WelsLogicalProcessInfo* p
|
||||
|
||||
#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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user