3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef THREADS_HEADER
21 #define THREADS_HEADER
24 // Determine which threading API we will use
26 #if __cplusplus >= 201103L
27 #define USE_CPP11_THREADS 1
29 #define USE_WIN_THREADS 1
31 #define USE_POSIX_THREADS 1
41 #include "threading/mutex.h"
44 // threadid_t, threadhandle_t
47 typedef std::thread::id threadid_t;
48 typedef std::thread::native_handle_type threadhandle_t;
50 typedef DWORD threadid_t;
51 typedef HANDLE threadhandle_t;
52 #elif USE_POSIX_THREADS
53 typedef pthread_t threadid_t;
54 typedef pthread_t threadhandle_t;
60 #if USE_CPP11_THREADS || USE_POSIX_THREADS
61 typedef void *ThreadStartFunc(void *param);
62 #elif defined(_WIN32_WCE)
63 typedef DWORD ThreadStartFunc(LPVOID param);
65 typedef DWORD WINAPI ThreadStartFunc(LPVOID param);
69 inline threadid_t thr_get_current_thread_id()
72 return std::this_thread::get_id();
74 return GetCurrentThreadId();
75 #elif USE_POSIX_THREADS
76 return pthread_self();
80 inline bool thr_compare_thread_id(threadid_t thr1, threadid_t thr2)
83 return pthread_equal(thr1, thr2);
89 inline bool thr_is_current_thread(threadid_t thr)
91 return thr_compare_thread_id(thr_get_current_thread_id(), thr);