diff options
author | sfan5 <sfan5@live.de> | 2016-10-06 21:13:04 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2016-10-06 22:37:30 +0200 |
commit | 0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7 (patch) | |
tree | e51a3209f5d3215bd9ab55311b0e4702ce3e9fca /src/threading/thread.cpp | |
parent | 155288ee981c70f505526347cb2bcda4df1c8e6b (diff) | |
download | minetest-0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7.tar.gz minetest-0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7.tar.bz2 minetest-0a16e53b40d347db7dcd04cb694d0f8f2ed1a5a7.zip |
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.
Diffstat (limited to 'src/threading/thread.cpp')
-rw-r--r-- | src/threading/thread.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
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); |