RTI Connext DDS Micro  Version 2.4.11
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
osapi_thread.h
Go to the documentation of this file.
1 /*
2  * FILE: osapi_thread.h - Definition of System API
3  *
4  * Copyright 2012-2015 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 12mar2012,tk Written
14  */
15 /*e \file
16  * \brief Thread interface definition
17  */
18 #ifndef osapi_thread_h
19 #define osapi_thread_h
20 
21 #include "osapi/osapi_config.h"
22 #ifndef osapi_dll_h
23 #include "osapi/osapi_dll.h"
24 #endif
25 #ifndef osapi_types_h
26 #include "osapi/osapi_types.h"
27 #endif
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 /*e \defgroup OSAPI_ThreadClass OSAPI Thread
35  * \ingroup OSAPIModule
36 */
37 
38 /* these are #defined so users can pass in any int they want for priority as well
39  * i.e., OS-native thread priorities
40  */
41 #define OSAPI_THREAD_PRIORITY_LOW -1
42 #define OSAPI_THREAD_PRIORITY_BELOW_NORMAL -2
43 #define OSAPI_THREAD_PRIORITY_NORMAL -3
44 #define OSAPI_THREAD_PRIORITY_ABOVE_NORMAL -4
45 #define OSAPI_THREAD_PRIORITY_HIGH -5
46 
47 #define OSAPI_THREAD_USE_OSDEFAULT_STACKSIZE 0
48 
49 /*e \ingroup OSAPI_ThreadClass
50  * Thread options
51  */
52 typedef RTI_UINT32 OSAPI_ThreadOptions;
53 
54 /*e \ingroup OSAPI_ThreadClass
55  Use only the default options the OS gives you.
56 */
57 #define OSAPI_THREAD_DEFAULT_OPTIONS 0x00
58 /*e \ingroup OSAPI_ThreadClass
59  Support floating point.
60 */
61 #define OSAPI_THREAD_FLOATING_POINT 0x01
62 /*e \ingroup OSAPI_ThreadClass
63  Support standard I/O.
64 */
65 #define OSAPI_THREAD_STDIO 0x02
66 /*e \ingroup OSAPI_ThreadClass
67  Run in real-time priority mode.
68 */
69 #define OSAPI_THREAD_REALTIME_PRIORITY 0x08
70 /*e \ingroup OSAPI_ThreadClass
71  Insist on the specified priority and fail if the OS doesn't like it.
72 */
73 #define OSAPI_THREAD_PRIORITY_ENFORCE 0x10
74 /*e \ingroup OSAPI_ThreadClass
75  Support the ability to asynchronously cancel the thread.
76 */
77 #define OSAPI_THREAD_CANCEL_ASYNCHRONOUS 0x20
78 
79 /*e \ingroup OSAPI_ThreadClass
80  Support the ability to suspend the thread. This is primarily for receive
81  threads.
82 */
83 #define OSAPI_THREAD_SUSPEND_ENABLE 0x40
84 
85 /*e \ingroup OSAPI_ThreadClass
86  *
87  */
88 struct OSAPI_ThreadProperty
89 {
90  /*e Hint on required stack-size */
91  RTI_UINT32 stack_size;
92 
93  /*e Hint on required priority */
94  RTI_INT32 priority;
95 
96  /*e Hint on thread priorites if support by the OS */
97  OSAPI_ThreadOptions options;
98 };
99 
100 /*e \ingroup OSAPI_ThreadClass
101  * Initializer for thread properties
102  */
103 #define OSAPI_THREAD_PROPERTY_DEFAULT \
104 { \
105  OSAPI_THREAD_USE_OSDEFAULT_STACKSIZE, \
106  OSAPI_THREAD_PRIORITY_NORMAL, \
107  OSAPI_THREAD_DEFAULT_OPTIONS \
108 }
109 
110 #define OSAPI_ThreadProperty_INITIALIZER OSAPI_THREAD_PROPERTY_DEFAULT
111 /*e
112  * \ingroup OSAPI_ThreadClass
113  * \brief Thread info
114  *
115  */
117 {
118  /*e Stop executing thread */
119  RTI_BOOL stop_thread;
120 
121  /*e Whether or not the created thread is preemptive */
122  RTI_BOOL is_premptive;
123 
124  /*e Parameter passed by thread creator. Passed to thread. */
125  void *user_data;
126 };
127 
128 /*e \ingroup OSAPI_ThreadClass
129  *
130  * \brief Thread task signature.
131  *
132  * \param[in] thread_info Thread information structure
133  *
134  * \return RTI_TRUE on successful execution, RTI_FALSE on failure.
135  */
136 FUNCTION_SHOULD_TYPEDEF(
137 RTI_BOOL
138 (*OSAPI_ThreadRoutine)(struct OSAPI_ThreadInfo *thread_info)
139 )
140 
141 /*e \ingroup OSAPI_ThreadClass
142  *
143  * \brief Abstract thread class.
144  */
145 struct OSAPI_Thread;
146 
147 
148 /*e \ingroup OSAPI_ThreadClass
149  *
150  * \brief Wakeup user-thread
151  *
152  * \details
153  *
154  * If a user-defined thread function is blocking, e.g. waiting for
155  * data, and the user wants to delete the thread, it is necessary to
156  * unblock the user-thread. The user must provide a function which can
157  * unblock a thread. This function calls the wake up function to wake up a
158  * blocked user thread.
159  *
160  * \param [in] self OSAPI_Thread to wakeup
161  *
162  * \return RTI_TRUE on success, RTI_FALSE on failure.
163  *
164  * \sa \ref OSAPI_Thread_start
165  */
166 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
167 OSAPI_Thread_wakeup(struct OSAPI_Thread *self);
168 
169 /*e \ingroup OSAPI_ThreadClass
170  *
171  * \brief Start a specific thread.
172  *
173  * \param [in] me Thread to wake up
174  *
175  * \return RTI_TRUE on success, RTI_FALSE on failure.
176  *
177  * \sa \ref OSAPI_Thread_create
178  */
179 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
180 OSAPI_Thread_start(struct OSAPI_Thread *me);
181 
182 
183 /*e \ingroup OSAPI_ThreadClass
184  * \brief Destroy a specific thread.
185  *
186  * \param [in] self Thread.
187  *
188  * \return RTI_TRUE on success, RTI_FALSE on failure.
189  *
190  * \sa \ref OSAPI_Thread_create
191  */
192 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
193 OSAPI_Thread_destroy(struct OSAPI_Thread *self);
194 
195 /*e \ingroup OSAPI_ThreadClass
196  * \brief Suspend a thread for a specified amount of time.
197  *
198  * \param [in] ms Sleep time.
199  *
200  */
201 OSAPIDllExport void
202 OSAPI_Thread_sleep(RTI_UINT32 ms);
203 
204 /*e \ingroup OSAPI_ThreadClass
205  *
206  * \brief Create a thread.
207  *
208  * \param [in] name The name of the thread.
209  *
210  * \param [in] properties Thread properties. These properties are hints.
211  *
212  * \param [in] user_routine Thread task. The thread task cannot assume that
213  * it can block; thus it must be written such that
214  * it can be called repeatedly.
215  *
216  * \param [in] user_data Parameters passed to the thread task.
217  *
218  * \param [in] wakeup_routine Routine to wake up a thread, called to delete
219  * a thread.
220  *
221  * \return Handle to stopped thread on success, NULL on failure.
222  *
223  * \sa \ref OSAPI_Thread_destroy
224  */
225 MUST_CHECK_RETURN OSAPIDllExport struct OSAPI_Thread*
226 OSAPI_Thread_create(const char *name,
227  const struct OSAPI_ThreadProperty *properties,
228  OSAPI_ThreadRoutine user_routine,
229  void *user_data,
230  OSAPI_ThreadRoutine wakeup_routine);
231 
232 
233 /*e \ingroup OSAPI_ThreadClass
234  *
235  * \brief Return thread ID.
236  *
237  * \return thread ID of the calling thread.
238  *
239  * \sa \ref OSAPI_Thread_create
240  */
241 OSAPIDllExport OSAPI_ThreadId
242 OSAPI_Thread_self(void);
243 
244 #ifdef __cplusplus
245 } /* extern "C" */
246 #endif
247 
248 
249 #endif /* osapi_thread_h */

RTI Connext DDS Micro Version 2.4.11 Copyright © Mon Jul 23 2018 Real-Time Innovations, Inc