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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019