From 0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 6 Oct 2016 21:13:04 +0200 Subject: Fix C++11 Windows build of threading code The initial problem was that mutex_auto_lock.h tries to use std::unique_lock 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. --- src/threading/thread.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/threading/thread.cpp') diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index 0cd536795..fbe4ba1f3 100644 --- a/src/threading/thread.cpp +++ b/src/threading/thread.cpp @@ -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); -- cgit v1.2.3