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



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019