Fix C++11 Windows build of threading code
The initial problem was that mutex_auto_lock.h tries to use std::unique_lock<std::mutex> despite mutex.h not using C++11's std::mutex on Windows. The problem here is the mismatch between C++11 usage conditions of the two headers. This commit moves the decision logic to threads.h and makes sure mutex.h, mutex_auto_lock.h and event.h all use the same features.
This commit is contained in:
@@ -198,7 +198,7 @@ bool Thread::kill()
|
||||
|
||||
m_running = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
#if USE_WIN_THREADS
|
||||
TerminateThread(m_thread_handle, 0);
|
||||
CloseHandle(m_thread_handle);
|
||||
#else
|
||||
@@ -310,10 +310,16 @@ void Thread::setName(const std::string &name)
|
||||
|
||||
unsigned int Thread::getNumberOfProcessors()
|
||||
{
|
||||
#if __cplusplus >= 201103L
|
||||
#if USE_CPP11_THREADS
|
||||
|
||||
return std::thread::hardware_concurrency();
|
||||
|
||||
#elif USE_WIN_THREADS
|
||||
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
return sysinfo.dwNumberOfProcessors;
|
||||
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
|
||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||
@@ -335,12 +341,6 @@ unsigned int Thread::getNumberOfProcessors()
|
||||
|
||||
return get_nprocs();
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
return sysinfo.dwNumberOfProcessors;
|
||||
|
||||
#elif defined(PTW32_VERSION) || defined(__hpux)
|
||||
|
||||
return pthread_num_processors_np();
|
||||
@@ -359,7 +359,7 @@ bool Thread::bindToProcessor(unsigned int proc_number)
|
||||
|
||||
return false;
|
||||
|
||||
#elif defined(_WIN32)
|
||||
#elif USE_WIN_THREADS
|
||||
|
||||
return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number);
|
||||
|
||||
@@ -407,7 +407,7 @@ bool Thread::bindToProcessor(unsigned int proc_number)
|
||||
|
||||
bool Thread::setPriority(int prio)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#if USE_WIN_THREADS
|
||||
|
||||
return SetThreadPriority(getThreadHandle(), prio);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user