summaryrefslogtreecommitdiff
path: root/src/threads.h
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-06-08 10:40:11 +0200
committerGitHub <noreply@github.com>2017-06-08 10:40:11 +0200
commit5bd33a158688f5fb950613278eefb95b0594a765 (patch)
treeaeeb82fafbc6559b68077f116df7200a63def657 /src/threads.h
parent0a5c3c28522f512f31dae3091668126c1eae787d (diff)
downloadminetest-5bd33a158688f5fb950613278eefb95b0594a765.tar.gz
minetest-5bd33a158688f5fb950613278eefb95b0594a765.tar.bz2
minetest-5bd33a158688f5fb950613278eefb95b0594a765.zip
C++11 patchset 5: use std::threads and remove old compat layer (#5928)
* C++11 patchset 5: use std::threads and remove old compat layer * use pragma once in modified headers * use C++11 function delete for object copy
Diffstat (limited to 'src/threads.h')
-rw-r--r--src/threads.h69
1 files changed, 6 insertions, 63 deletions
diff --git a/src/threads.h b/src/threads.h
index 9731dcb5e..ea84abd3e 100644
--- a/src/threads.h
+++ b/src/threads.h
@@ -1,6 +1,7 @@
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -17,92 +18,34 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef THREADS_HEADER
-#define THREADS_HEADER
-
-//
-// Determine which threading APIs we will use
-//
-#if __cplusplus >= 201103L
- #define USE_CPP11_THREADS 1
-#elif defined(_WIN32)
- #define USE_WIN_THREADS 1
-#else
- #define USE_POSIX_THREADS 1
-#endif
-
-#if defined(_WIN32)
- // Prefer critical section API because std::mutex is much slower on Windows
- #define USE_WIN_MUTEX 1
-#elif __cplusplus >= 201103L
- #define USE_CPP11_MUTEX 1
-#else
- #define USE_POSIX_MUTEX 1
-#endif
+#pragma once
///////////////
-
-
-#if USE_CPP11_THREADS
- #include <thread>
-#elif USE_POSIX_THREADS
- #include <pthread.h>
-#else
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif
- #include <windows.h>
-#endif
+#include <thread>
//
// threadid_t, threadhandle_t
//
-#if USE_CPP11_THREADS
- typedef std::thread::id threadid_t;
- typedef std::thread::native_handle_type threadhandle_t;
-#elif USE_WIN_THREADS
- typedef DWORD threadid_t;
- typedef HANDLE threadhandle_t;
-#elif USE_POSIX_THREADS
- typedef pthread_t threadid_t;
- typedef pthread_t threadhandle_t;
-#endif
+typedef std::thread::id threadid_t;
+typedef std::thread::native_handle_type threadhandle_t;
//
// ThreadStartFunc
//
-#if USE_CPP11_THREADS || USE_POSIX_THREADS
- typedef void *ThreadStartFunc(void *param);
-#elif defined(_WIN32_WCE)
- typedef DWORD ThreadStartFunc(LPVOID param);
-#elif defined(_WIN32)
- typedef DWORD WINAPI ThreadStartFunc(LPVOID param);
-#endif
+typedef void *ThreadStartFunc(void *param);
inline threadid_t thr_get_current_thread_id()
{
-#if USE_CPP11_THREADS
return std::this_thread::get_id();
-#elif USE_WIN_THREADS
- return GetCurrentThreadId();
-#elif USE_POSIX_THREADS
- return pthread_self();
-#endif
}
inline bool thr_compare_thread_id(threadid_t thr1, threadid_t thr2)
{
-#if USE_POSIX_THREADS
- return pthread_equal(thr1, thr2);
-#else
return thr1 == thr2;
-#endif
}
inline bool thr_is_current_thread(threadid_t thr)
{
return thr_compare_thread_id(thr_get_current_thread_id(), thr);
}
-
-#endif