osx fixes
parent
263d672637
commit
c900bea6b6
|
@ -311,11 +311,13 @@ void Thread::setCoreAffinity(int coreID) {
|
||||||
if (!d->running)
|
if (!d->running)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if defined(__OSX__)
|
||||||
|
/* CPU affinity not supported on OSX */
|
||||||
|
#elif defined(__LINUX__)
|
||||||
int nCores = getCoreCount();
|
int nCores = getCoreCount();
|
||||||
#if defined(__LINUX__) || defined(__OSX__)
|
|
||||||
cpu_set_t *cpuset = CPU_ALLOC(nCores);
|
cpu_set_t *cpuset = CPU_ALLOC(nCores);
|
||||||
if (cpuset == NULL)
|
if (cpuset == NULL)
|
||||||
Log(EError, "Thread::setCoreAffinity: could not allocate cpu_set_t");
|
Log(EError, "Thread::setCoreAffinity(): could not allocate cpu_set_t");
|
||||||
|
|
||||||
size_t size = CPU_ALLOC_SIZE(nCores);
|
size_t size = CPU_ALLOC_SIZE(nCores);
|
||||||
CPU_ZERO_S(size, cpuset);
|
CPU_ZERO_S(size, cpuset);
|
||||||
|
@ -328,8 +330,21 @@ void Thread::setCoreAffinity(int coreID) {
|
||||||
|
|
||||||
const pthread_t threadID = d->thread.native_handle();
|
const pthread_t threadID = d->thread.native_handle();
|
||||||
if (pthread_setaffinity_np(threadID, size, cpuset) != 0)
|
if (pthread_setaffinity_np(threadID, size, cpuset) != 0)
|
||||||
Log(EWarn, "pthread_setaffinity_np: failed");
|
Log(EWarn, "Thread::setCoreAffinity(): pthread_setaffinity_np: failed");
|
||||||
CPU_FREE(cpuset);
|
CPU_FREE(cpuset);
|
||||||
|
#elif defined(__WINDOWS__)
|
||||||
|
int nCores = getCoreCount();
|
||||||
|
const HANDLE handle = d->thread.native_handle();
|
||||||
|
|
||||||
|
DWORD_PTR mask;
|
||||||
|
|
||||||
|
if (coreID != -1 && coreID < nCores)
|
||||||
|
mask = (DWORD_PTR) 1 << coreID;
|
||||||
|
else
|
||||||
|
mask = (1 << nCores) - 1;
|
||||||
|
|
||||||
|
if (!SetThreadAffinityMask(handle, mask))
|
||||||
|
Log(EWarn, "Thread::setCoreAffinity(): SetThreadAffinityMask : failed");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,10 +478,11 @@ void Thread::staticInitialization() {
|
||||||
#if defined(MTS_OPENMP)
|
#if defined(MTS_OPENMP)
|
||||||
__omp_threadCount = omp_get_max_threads();
|
__omp_threadCount = omp_get_max_threads();
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(__LINUX__)
|
||||||
|
pthread_key_create(&__thread_id, NULL);
|
||||||
#endif
|
#endif
|
||||||
detail::initializeGlobalTLS();
|
detail::initializeGlobalTLS();
|
||||||
detail::initializeLocalTLS();
|
detail::initializeLocalTLS();
|
||||||
pthread_key_create(&__thread_id, NULL);
|
|
||||||
|
|
||||||
ThreadPrivate::self = new ThreadLocal<Thread>();
|
ThreadPrivate::self = new ThreadLocal<Thread>();
|
||||||
Thread *mainThread = new MainThread();
|
Thread *mainThread = new MainThread();
|
||||||
|
@ -500,6 +516,9 @@ void Thread::staticShutdown() {
|
||||||
delete ThreadPrivate::self;
|
delete ThreadPrivate::self;
|
||||||
ThreadPrivate::self = NULL;
|
ThreadPrivate::self = NULL;
|
||||||
detail::destroyGlobalTLS();
|
detail::destroyGlobalTLS();
|
||||||
|
#if defined(__LINUX__)
|
||||||
|
pthread_key_delete(__thread_id);
|
||||||
|
#endif
|
||||||
#if defined(__OSX__)
|
#if defined(__OSX__)
|
||||||
#if defined(MTS_OPENMP)
|
#if defined(MTS_OPENMP)
|
||||||
if (__omp_key_created)
|
if (__omp_key_created)
|
||||||
|
|
Loading…
Reference in New Issue