MRPT  1.9.9
xsthread.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef XSTHREAD_H
10 #define XSTHREAD_H
11 
12 #include "xstime.h"
13 #if defined(XSENS_DEBUG) && defined(_MSC_VER)
14 #pragma warning(disable : 4985)
15 #include <intrin.h>
16 #endif
17 
18 #ifndef __GNUC__
19 #pragma warning(push)
20 #pragma warning(disable : 4127)
21 #endif
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #ifdef XSENS_WINDOWS
28 #ifndef WINVER // Allow use of features specific to Windows XP or later.
29 #define WINVER \
30  0x0502 // Change this to the appropriate value to target other versions of
31 // Windows.
32 #endif
33 
34 #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
35 #define _WIN32_WINNT \
36  0x0502 // Change this to the appropriate value to target other versions of
37 // Windows.
38 #endif
39 
40 #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or
41 // later.
42 #define _WIN32_WINDOWS \
43  0x0410 // Change this to the appropriate value to target Windows Me or
44 // later.
45 #endif
46 
47 #ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
48 #define _WIN32_IE \
49  0x0600 // Change this to the appropriate value to target other versions of
50 // IE.
51 #endif
52 
53 #include <windows.h>
54 
55 /*! \addtogroup enums Global enumerations
56  @{
57 */
58 /*! \brief Thread priorities for xsSetThreadPriority() and xsGetThreadPriority()
59 */
61 {
62  XS_THREAD_PRIORITY_LOWEST = THREAD_PRIORITY_IDLE,
63  XS_THREAD_PRIORITY_LOWER = THREAD_PRIORITY_LOWEST,
64  XS_THREAD_PRIORITY_LOW = THREAD_PRIORITY_BELOW_NORMAL,
65  XS_THREAD_PRIORITY_NORMAL = THREAD_PRIORITY_NORMAL,
66  XS_THREAD_PRIORITY_HIGH = THREAD_PRIORITY_ABOVE_NORMAL,
67  XS_THREAD_PRIORITY_HIGHER = THREAD_PRIORITY_HIGHEST,
68  XS_THREAD_PRIORITY_HIGHEST = THREAD_PRIORITY_TIME_CRITICAL
69 };
70 /*! @} */
71 
72 // The components of the type of a thread function
73 #define XSENS_THREAD_RETURN DWORD
74 #define XSENS_THREAD_TYPE WINAPI
75 #define XSENS_THREAD_PARAM LPVOID
76 
77 #define XSENS_INVALID_THREAD INVALID_HANDLE_VALUE
78 
79 /*! \brief Release the remainder of the timeslice so other operations can run.
80  On Windows this is done using Sleep(0), since this is the most reliable
81  method.
82  SwitchToThread can cause delays since it does not allow the thread to resume
83  on a different core.
84  Sleep http://msdn.microsoft.com/en-us/library/ms686298%28v=vs.85%29.aspx
85  SwitchToThread
86  http://msdn.microsoft.com/en-us/library/ms686352%28v=vs.85%29.aspx
87 */
88 #define xsYield() Sleep(0)
89 
90 //! A handle for a thread
91 typedef HANDLE XsThread;
92 #ifdef __cplusplus
93 typedef ::DWORD XsThreadId;
94 #else
95 typedef DWORD XsThreadId;
96 #endif
97 
98 //! Start a function as a thread
99 #define xsStartThread(func, param, pid) \
100  CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)func, param, 0, pid)
101 
102 XSTYPES_DLL_API void xsNameThisThread(const char* threadName);
103 
104 #define xsGetCurrentThreadId() GetCurrentThreadId()
105 #define xsGetCurrentThreadHandle() GetCurrentThread()
106 #define xsSuspendThread(thrd) SuspendThread(thrd)
107 #define xsResumeThread(thrd) ResumeThread(thrd)
108 #define xsSetThreadPriority(thrd, prio) SetThreadPriority(thrd, prio)
109 #define xsGetThreadPriority(thrd) GetThreadPriority(thrd)
110 
111 #else
112 #include <pthread.h>
113 #include <semaphore.h>
114 #include <errno.h>
115 //#define XSENS_USE_POSIX_LOCKING 1
116 
117 /*! \addtogroup enums Global enumerations
118  @{
119 */
120 /*! \brief Thread priorities for xsSetThreadPriority() and xsGetThreadPriority()
121 */
122 enum XsThreadPriority
123 {
124  XS_THREAD_PRIORITY_LOWEST = 0, // THREAD_PRIORITY_IDLE,
125  XS_THREAD_PRIORITY_LOWER = 1, // THREAD_PRIORITY_LOWEST,
126  XS_THREAD_PRIORITY_LOW = 2, // THREAD_PRIORITY_BELOW_NORMAL,
127  XS_THREAD_PRIORITY_NORMAL = 3, // THREAD_PRIORITY_NORMAL,
128  XS_THREAD_PRIORITY_HIGH = 4, // THREAD_PRIORITY_ABOVE_NORMAL,
129  XS_THREAD_PRIORITY_HIGHER = 5, // THREAD_PRIORITY_HIGHEST,
130  XS_THREAD_PRIORITY_HIGHEST = 6 // THREAD_PRIORITY_TIME_CRITICAL
131 };
132 /*! @} */
133 
134 // The components of the type of a thread function
135 #define XSENS_THREAD_RETURN void* // DWORD
136 #define XSENS_THREAD_TYPE // WINAPI
137 #define XSENS_THREAD_PARAM void* // LPVOID
138 
139 #define XSENS_INVALID_THREAD 0 // INVALID_HANDLE_VALUE
140 
141 //! Release the remainder of the timeslice so other operations can run.
142 #ifdef __APPLE__
143 #define xsYield() pthread_yield_np()
144 #else
145 #define xsYield() pthread_yield() // Sleep(0)
146 #endif
147 
148 void xsNameThisThread(const char* threadName);
149 //! A handle for a thread
150 typedef pthread_t XsThread;
151 typedef pthread_t XsThreadId;
152 
153 //! Start a function as a thread
154 pthread_t xsStartThread(void*(func)(void*), void* param, void* pid);
155 #define xsGetCurrentThreadId() pthread_self()
156 #define xsSuspendThread(thrd)
157 #define xsResumeThread(thrd)
158 #define xsSetThreadPriority(thrd, prio)
159 
160 #endif // _WIN32
161 
162 #ifndef __GNUC__
163 #pragma warning(pop)
164 #endif
165 
166 #ifdef __cplusplus
167 } // extern "C"
168 #endif
169 
171 
172 #endif // file guard
#define xsStartThread(func, param, pid)
Start a function as a thread.
Definition: xsthread.h:99
XsThreadPriority
Thread priorities for xsSetThreadPriority() and xsGetThreadPriority()
Definition: xsthread.h:60
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:9
HANDLE XsThread
A handle for a thread.
Definition: xsthread.h:91
DWORD XsThreadId
Definition: xsthread.h:95
GLfloat param
Definition: glext.h:3831
XSTYPES_DLL_API void xsNameThisThread(const char *threadName)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020