1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Constants and Structures Needed to Declare a Thread Queue |
---|
5 | * |
---|
6 | * This include file contains all the constants and structures |
---|
7 | * needed to declare a thread queue. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2014. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_THREADQ_H |
---|
20 | #define _RTEMS_SCORE_THREADQ_H |
---|
21 | |
---|
22 | #include <rtems/score/chain.h> |
---|
23 | #include <rtems/score/isrlock.h> |
---|
24 | #include <rtems/score/object.h> |
---|
25 | #include <rtems/score/priority.h> |
---|
26 | #include <rtems/score/rbtree.h> |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | /** |
---|
33 | * @defgroup ScoreThreadQueue Thread Queue Handler |
---|
34 | * |
---|
35 | * @ingroup Score |
---|
36 | * |
---|
37 | * This handler provides the capability to have threads block in |
---|
38 | * ordered sets. The sets may be ordered using the FIFO or priority |
---|
39 | * discipline. |
---|
40 | */ |
---|
41 | /**@{*/ |
---|
42 | |
---|
43 | typedef struct _Thread_Control Thread_Control; |
---|
44 | |
---|
45 | #if defined(RTEMS_MULTIPROCESSING) |
---|
46 | /** |
---|
47 | * @brief Multiprocessing (MP) support callout for thread queue operations. |
---|
48 | * |
---|
49 | * @param the_proxy The thread proxy of the thread queue operation. A thread |
---|
50 | * control is actually a thread proxy if and only if |
---|
51 | * _Objects_Is_local_id( the_proxy->Object.id ) is false. |
---|
52 | * @param mp_id Object identifier of the object containing the thread queue. |
---|
53 | */ |
---|
54 | typedef void ( *Thread_queue_MP_callout )( |
---|
55 | Thread_Control *the_proxy, |
---|
56 | Objects_Id mp_id |
---|
57 | ); |
---|
58 | #endif |
---|
59 | |
---|
60 | /** |
---|
61 | * @brief Thread queue context for the thread queue methods. |
---|
62 | * |
---|
63 | * @see _Thread_queue_Context_initialize(). |
---|
64 | */ |
---|
65 | typedef struct { |
---|
66 | /** |
---|
67 | * @brief The lock context for the thread queue acquire and release |
---|
68 | * operations. |
---|
69 | */ |
---|
70 | ISR_lock_Context Lock_context; |
---|
71 | |
---|
72 | /** |
---|
73 | * @brief Callout to unblock the thread in case it is actually a thread |
---|
74 | * proxy. |
---|
75 | * |
---|
76 | * This field is only used on multiprocessing configurations. Used by |
---|
77 | * thread queue extract and unblock methods for objects with multiprocessing |
---|
78 | * (MP) support. |
---|
79 | * |
---|
80 | * @see _Thread_queue_Context_set_MP_callout(). |
---|
81 | */ |
---|
82 | #if defined(RTEMS_MULTIPROCESSING) |
---|
83 | Thread_queue_MP_callout mp_callout; |
---|
84 | #endif |
---|
85 | } Thread_queue_Context; |
---|
86 | |
---|
87 | /** |
---|
88 | * @brief Thread priority queue. |
---|
89 | */ |
---|
90 | typedef struct { |
---|
91 | #if defined(RTEMS_SMP) |
---|
92 | /** |
---|
93 | * @brief Node to enqueue this queue in the FIFO chain of the corresponding |
---|
94 | * heads structure. |
---|
95 | * |
---|
96 | * @see Thread_queue_Heads::Heads::Fifo. |
---|
97 | */ |
---|
98 | Chain_Node Node; |
---|
99 | #endif |
---|
100 | |
---|
101 | /** |
---|
102 | * @brief The actual thread priority queue. |
---|
103 | */ |
---|
104 | RBTree_Control Queue; |
---|
105 | } Thread_queue_Priority_queue; |
---|
106 | |
---|
107 | /** |
---|
108 | * @brief Thread queue heads. |
---|
109 | * |
---|
110 | * Each thread is equipped with spare thread queue heads in case it is not |
---|
111 | * enqueued on a thread queue. The first thread enqueued on a thread queue |
---|
112 | * will give its spare thread queue heads to that thread queue. The threads |
---|
113 | * arriving at the queue will add their thread queue heads to the free chain of |
---|
114 | * the queue heads provided by the first thread enqueued. Once a thread is |
---|
115 | * dequeued it use the free chain to get new spare thread queue heads. |
---|
116 | * |
---|
117 | * Uses a leading underscore in the structure name to allow forward |
---|
118 | * declarations in standard header files provided by Newlib and GCC. |
---|
119 | */ |
---|
120 | typedef struct _Thread_queue_Heads { |
---|
121 | /** This union contains the data structures used to manage the blocked |
---|
122 | * set of tasks which varies based upon the discipline. |
---|
123 | */ |
---|
124 | union { |
---|
125 | /** |
---|
126 | * @brief This is the FIFO discipline list. |
---|
127 | * |
---|
128 | * On SMP configurations this FIFO is used to enqueue the per scheduler |
---|
129 | * instance priority queues of this structure. This ensures FIFO fairness |
---|
130 | * among the highest priority thread of each scheduler instance. |
---|
131 | */ |
---|
132 | Chain_Control Fifo; |
---|
133 | |
---|
134 | #if !defined(RTEMS_SMP) |
---|
135 | /** |
---|
136 | * @brief This is the set of threads for priority discipline waiting. |
---|
137 | */ |
---|
138 | Thread_queue_Priority_queue Priority; |
---|
139 | #endif |
---|
140 | } Heads; |
---|
141 | |
---|
142 | /** |
---|
143 | * @brief A chain with free thread queue heads providing the spare thread |
---|
144 | * queue heads for a thread once it is dequeued. |
---|
145 | */ |
---|
146 | Chain_Control Free_chain; |
---|
147 | |
---|
148 | /** |
---|
149 | * @brief A chain node to add these thread queue heads to the free chain of |
---|
150 | * the thread queue heads dedicated to the thread queue of an object. |
---|
151 | */ |
---|
152 | Chain_Node Free_node; |
---|
153 | |
---|
154 | #if defined(RTEMS_SMP) |
---|
155 | /** |
---|
156 | * @brief One priority queue per scheduler instance. |
---|
157 | */ |
---|
158 | Thread_queue_Priority_queue Priority[ RTEMS_ZERO_LENGTH_ARRAY ]; |
---|
159 | #endif |
---|
160 | } Thread_queue_Heads; |
---|
161 | |
---|
162 | #if defined(RTEMS_SMP) |
---|
163 | #define THREAD_QUEUE_HEADS_SIZE( scheduler_count ) \ |
---|
164 | ( sizeof( Thread_queue_Heads ) \ |
---|
165 | + ( scheduler_count ) * sizeof( Thread_queue_Priority_queue ) ) |
---|
166 | #else |
---|
167 | #define THREAD_QUEUE_HEADS_SIZE( scheduler_count ) \ |
---|
168 | sizeof( Thread_queue_Heads ) |
---|
169 | #endif |
---|
170 | |
---|
171 | typedef struct { |
---|
172 | /** |
---|
173 | * @brief Lock to protect this thread queue. |
---|
174 | * |
---|
175 | * It may be used to protect additional state of the object embedding this |
---|
176 | * thread queue. |
---|
177 | * |
---|
178 | * Must be the first component of this structure to be able to re-use |
---|
179 | * implementation parts for structures defined by Newlib <sys/lock.h>. |
---|
180 | * |
---|
181 | * @see _Thread_queue_Acquire(), _Thread_queue_Acquire_critical() and |
---|
182 | * _Thread_queue_Release(). |
---|
183 | */ |
---|
184 | #if defined(RTEMS_SMP) |
---|
185 | SMP_ticket_lock_Control Lock; |
---|
186 | #endif |
---|
187 | |
---|
188 | /** |
---|
189 | * @brief The thread queue heads. |
---|
190 | * |
---|
191 | * This pointer is NULL, if and only if no threads are enqueued. The first |
---|
192 | * thread to enqueue will give its spare thread queue heads to this thread |
---|
193 | * queue. |
---|
194 | */ |
---|
195 | Thread_queue_Heads *heads; |
---|
196 | |
---|
197 | /** |
---|
198 | * @brief The thread queue owner. |
---|
199 | */ |
---|
200 | Thread_Control *owner; |
---|
201 | } Thread_queue_Queue; |
---|
202 | |
---|
203 | /** |
---|
204 | * @brief Thread queue priority change operation. |
---|
205 | * |
---|
206 | * @param[in] the_thread The thread. |
---|
207 | * @param[in] new_priority The new priority value. |
---|
208 | * @param[in] queue The actual thread queue. |
---|
209 | * |
---|
210 | * @see Thread_queue_Operations. |
---|
211 | */ |
---|
212 | typedef void ( *Thread_queue_Priority_change_operation )( |
---|
213 | Thread_Control *the_thread, |
---|
214 | Priority_Control new_priority, |
---|
215 | Thread_queue_Queue *queue |
---|
216 | ); |
---|
217 | |
---|
218 | /** |
---|
219 | * @brief Thread queue enqueue operation. |
---|
220 | * |
---|
221 | * @param[in] queue The actual thread queue. |
---|
222 | * @param[in] the_thread The thread to enqueue on the queue. |
---|
223 | * |
---|
224 | * @see _Thread_Wait_set_operations(). |
---|
225 | */ |
---|
226 | typedef void ( *Thread_queue_Enqueue_operation )( |
---|
227 | Thread_queue_Queue *queue, |
---|
228 | Thread_Control *the_thread |
---|
229 | ); |
---|
230 | |
---|
231 | /** |
---|
232 | * @brief Thread queue extract operation. |
---|
233 | * |
---|
234 | * @param[in] queue The actual thread queue. |
---|
235 | * @param[in] the_thread The thread to extract from the thread queue. |
---|
236 | * |
---|
237 | * @see _Thread_Wait_set_operations(). |
---|
238 | */ |
---|
239 | typedef void ( *Thread_queue_Extract_operation )( |
---|
240 | Thread_queue_Queue *queue, |
---|
241 | Thread_Control *the_thread |
---|
242 | ); |
---|
243 | |
---|
244 | /** |
---|
245 | * @brief Thread queue first operation. |
---|
246 | * |
---|
247 | * @param[in] heads The thread queue heads. |
---|
248 | * |
---|
249 | * @retval NULL No thread is present on the thread queue. |
---|
250 | * @retval first The first thread of the thread queue according to the insert |
---|
251 | * order. This thread remains on the thread queue. |
---|
252 | * |
---|
253 | * @see _Thread_Wait_set_operations(). |
---|
254 | */ |
---|
255 | typedef Thread_Control *( *Thread_queue_First_operation )( |
---|
256 | Thread_queue_Heads *heads |
---|
257 | ); |
---|
258 | |
---|
259 | /** |
---|
260 | * @brief Thread queue operations. |
---|
261 | * |
---|
262 | * @see _Thread_wait_Set_operations(). |
---|
263 | */ |
---|
264 | typedef struct { |
---|
265 | /** |
---|
266 | * @brief Thread queue priority change operation. |
---|
267 | * |
---|
268 | * Called by _Thread_Change_priority() to notify a thread about a priority |
---|
269 | * change. In case this thread waits currently for a resource the handler |
---|
270 | * may adjust its data structures according to the new priority value. This |
---|
271 | * handler must not be NULL, instead the default handler |
---|
272 | * _Thread_Do_nothing_priority_change() should be used in case nothing needs |
---|
273 | * to be done during a priority change. |
---|
274 | */ |
---|
275 | Thread_queue_Priority_change_operation priority_change; |
---|
276 | |
---|
277 | /** |
---|
278 | * @brief Thread queue enqueue operation. |
---|
279 | * |
---|
280 | * Called by object routines to enqueue the thread. |
---|
281 | */ |
---|
282 | Thread_queue_Enqueue_operation enqueue; |
---|
283 | |
---|
284 | /** |
---|
285 | * @brief Thread queue extract operation. |
---|
286 | * |
---|
287 | * Called by object routines to extract a thread from a thread queue. |
---|
288 | */ |
---|
289 | Thread_queue_Extract_operation extract; |
---|
290 | |
---|
291 | /** |
---|
292 | * @brief Thread queue first operation. |
---|
293 | */ |
---|
294 | Thread_queue_First_operation first; |
---|
295 | } Thread_queue_Operations; |
---|
296 | |
---|
297 | /** |
---|
298 | * This is the structure used to manage sets of tasks which are blocked |
---|
299 | * waiting to acquire a resource. |
---|
300 | */ |
---|
301 | typedef struct { |
---|
302 | #if defined(RTEMS_SMP) |
---|
303 | #if defined(RTEMS_DEBUG) |
---|
304 | /** |
---|
305 | * @brief The index of the owning processor of the thread queue lock. |
---|
306 | * |
---|
307 | * The thread queue lock may be acquired via the thread lock also. This path |
---|
308 | * is not covered by this field. In case the lock is not owned directly via |
---|
309 | * _Thread_queue_Acquire(), then the value of this field is |
---|
310 | * SMP_LOCK_NO_OWNER. |
---|
311 | * |
---|
312 | * Must be before the queue component of this structure to be able to re-use |
---|
313 | * implementation parts for structures defined by Newlib <sys/lock.h>. |
---|
314 | */ |
---|
315 | uint32_t owner; |
---|
316 | #endif |
---|
317 | |
---|
318 | #if defined(RTEMS_PROFILING) |
---|
319 | /** |
---|
320 | * @brief SMP lock statistics in case SMP and profiling are enabled. |
---|
321 | * |
---|
322 | * Must be before the queue component of this structure to be able to re-use |
---|
323 | * implementation parts for structures defined by Newlib <sys/lock.h>. |
---|
324 | */ |
---|
325 | SMP_lock_Stats Lock_stats; |
---|
326 | #endif |
---|
327 | #endif |
---|
328 | |
---|
329 | /** |
---|
330 | * @brief The actual thread queue. |
---|
331 | */ |
---|
332 | Thread_queue_Queue Queue; |
---|
333 | } Thread_queue_Control; |
---|
334 | |
---|
335 | /**@}*/ |
---|
336 | |
---|
337 | #ifdef __cplusplus |
---|
338 | } |
---|
339 | #endif |
---|
340 | |
---|
341 | #endif |
---|
342 | /* end of include file */ |
---|