summaryrefslogtreecommitdiff
path: root/src/threading/thread.cpp
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
committerest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
commit81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch)
tree1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /src/threading/thread.cpp
parent8077612dcb48221281e726a60eb97bf73fde462b (diff)
parent231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff)
downloadminetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'src/threading/thread.cpp')
-rw-r--r--src/threading/thread.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp
index 5161a6c01..fbe4ba1f3 100644
--- a/src/threading/thread.cpp
+++ b/src/threading/thread.cpp
@@ -54,7 +54,7 @@ DEALINGS IN THE SOFTWARE.
// for setName
-#if defined(linux) || defined(__linux)
+#if defined(__linux__)
#include <sys/prctl.h>
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
#include <pthread_np.h>
@@ -70,7 +70,7 @@ DEALINGS IN THE SOFTWARE.
// for bindToProcessor
#if __FreeBSD_version >= 702106
typedef cpuset_t cpu_set_t;
-#elif defined(__linux) || defined(linux)
+#elif defined(__linux__)
#include <sched.h>
#elif defined(__sun) || defined(sun)
#include <sys/types.h>
@@ -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
@@ -261,7 +261,7 @@ DWORD WINAPI Thread::threadProc(LPVOID param)
void Thread::setName(const std::string &name)
{
-#if defined(linux) || defined(__linux)
+#if defined(__linux__)
// It would be cleaner to do this with pthread_setname_np,
// which was added to glibc in version 2.12, but some major
@@ -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,11 +359,11 @@ bool Thread::bindToProcessor(unsigned int proc_number)
return false;
-#elif defined(_WIN32)
+#elif USE_WIN_THREADS
return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number);
-#elif __FreeBSD_version >= 702106 || defined(__linux) || defined(linux)
+#elif __FreeBSD_version >= 702106 || defined(__linux__)
cpu_set_t cpuset;
@@ -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);