1 | /** |
---|
2 | * @file rtems/score/threadq.h |
---|
3 | * |
---|
4 | * This include file contains all the constants and structures associated |
---|
5 | * with the manipulation of objects. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_THREADQ_H |
---|
20 | #define _RTEMS_SCORE_THREADQ_H |
---|
21 | |
---|
22 | /** |
---|
23 | * @defgroup ScoreThreadQ Thread Queue Handler |
---|
24 | * |
---|
25 | * This handler encapsulates functionality related to managing sets of threads |
---|
26 | * blocked waiting for resources. |
---|
27 | */ |
---|
28 | /**@{*/ |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif |
---|
33 | |
---|
34 | #include <rtems/score/tqdata.h> |
---|
35 | |
---|
36 | #include <rtems/score/object.h> |
---|
37 | #include <rtems/score/thread.h> |
---|
38 | #include <rtems/score/watchdog.h> |
---|
39 | |
---|
40 | /** |
---|
41 | * Constant for indefinite wait. |
---|
42 | */ |
---|
43 | #define THREAD_QUEUE_WAIT_FOREVER WATCHDOG_NO_TIMEOUT |
---|
44 | |
---|
45 | /** |
---|
46 | * The following type defines the callout used when a remote task |
---|
47 | * is extracted from a local thread queue. |
---|
48 | */ |
---|
49 | typedef void ( *Thread_queue_Flush_callout )( |
---|
50 | Thread_Control * |
---|
51 | ); |
---|
52 | |
---|
53 | /** |
---|
54 | * |
---|
55 | * The following type defines the callout used for timeout processing |
---|
56 | * methods. |
---|
57 | */ |
---|
58 | typedef void ( *Thread_queue_Timeout_callout )( |
---|
59 | Objects_Id, |
---|
60 | void * |
---|
61 | ); |
---|
62 | |
---|
63 | /** @brief Thread queue Dequeue |
---|
64 | * |
---|
65 | * This function returns a pointer to a thread waiting on |
---|
66 | * the_thread_queue. The selection of this thread is based on |
---|
67 | * the discipline of the_thread_queue. If no threads are waiting |
---|
68 | * on the_thread_queue, then NULL is returned. |
---|
69 | */ |
---|
70 | Thread_Control *_Thread_queue_Dequeue( |
---|
71 | Thread_queue_Control *the_thread_queue |
---|
72 | ); |
---|
73 | |
---|
74 | /** @brief Thread queue Enqueue Wrapper |
---|
75 | * |
---|
76 | * This routine enqueues the currently executing thread on |
---|
77 | * the_thread_queue with an optional timeout. |
---|
78 | */ |
---|
79 | #define _Thread_queue_Enqueue( _the_thread_queue, _timeout ) \ |
---|
80 | _Thread_queue_Enqueue_with_handler( \ |
---|
81 | _the_thread_queue, \ |
---|
82 | _timeout, \ |
---|
83 | _Thread_queue_Timeout ) |
---|
84 | |
---|
85 | |
---|
86 | /** @brief Thread queue Enqueue |
---|
87 | * |
---|
88 | * This routine enqueues the currently executing thread on |
---|
89 | * the_thread_queue with an optional timeout. |
---|
90 | */ |
---|
91 | void _Thread_queue_Enqueue_with_handler( |
---|
92 | Thread_queue_Control* the_thread_queue, |
---|
93 | Watchdog_Interval timeout, |
---|
94 | Thread_queue_Timeout_callout handler |
---|
95 | ); |
---|
96 | |
---|
97 | /** |
---|
98 | * @brief Thread queue Requeue |
---|
99 | * |
---|
100 | * This routine is invoked when a thread changes priority and is |
---|
101 | * blocked on a thread queue. If the queue is priority ordered, |
---|
102 | * the_thread is removed from the_thread_queue and reinserted using |
---|
103 | * its new priority. This method has no impact on the state of the_thread |
---|
104 | * or of any timeouts associated with this blocking. |
---|
105 | */ |
---|
106 | void _Thread_queue_Requeue( |
---|
107 | Thread_queue_Control *the_thread_queue, |
---|
108 | Thread_Control *the_thread |
---|
109 | ); |
---|
110 | |
---|
111 | /** @brief Thread queue Extract |
---|
112 | * |
---|
113 | * This routine removes the_thread from the_thread_queue |
---|
114 | * and cancels any timeouts associated with this blocking. |
---|
115 | */ |
---|
116 | void _Thread_queue_Extract( |
---|
117 | Thread_queue_Control *the_thread_queue, |
---|
118 | Thread_Control *the_thread |
---|
119 | ); |
---|
120 | |
---|
121 | /** @brief Thread queue Extract with proxy |
---|
122 | * |
---|
123 | * This routine extracts the_thread from the_thread_queue |
---|
124 | * and ensures that if there is a proxy for this task on |
---|
125 | * another node, it is also dealt with. |
---|
126 | */ |
---|
127 | boolean _Thread_queue_Extract_with_proxy( |
---|
128 | Thread_Control *the_thread |
---|
129 | ); |
---|
130 | |
---|
131 | /** @brief Thread queue First |
---|
132 | * |
---|
133 | * This function returns a pointer to the "first" thread |
---|
134 | * on the_thread_queue. The "first" thread is selected |
---|
135 | * based on the discipline of the_thread_queue. |
---|
136 | */ |
---|
137 | Thread_Control *_Thread_queue_First( |
---|
138 | Thread_queue_Control *the_thread_queue |
---|
139 | ); |
---|
140 | |
---|
141 | /** @brief Thread queue Flush |
---|
142 | * |
---|
143 | * This routine unblocks all threads blocked on the_thread_queue |
---|
144 | * and cancels any associated timeouts. |
---|
145 | */ |
---|
146 | void _Thread_queue_Flush( |
---|
147 | Thread_queue_Control *the_thread_queue, |
---|
148 | Thread_queue_Flush_callout remote_extract_callout, |
---|
149 | uint32_t status |
---|
150 | ); |
---|
151 | |
---|
152 | /** @brief Thread queue Initialize |
---|
153 | * |
---|
154 | * This routine initializes the_thread_queue based on the |
---|
155 | * discipline indicated in attribute_set. The state set on |
---|
156 | * threads which block on the_thread_queue is state. |
---|
157 | */ |
---|
158 | void _Thread_queue_Initialize( |
---|
159 | Thread_queue_Control *the_thread_queue, |
---|
160 | Thread_queue_Disciplines the_discipline, |
---|
161 | States_Control state, |
---|
162 | uint32_t timeout_status |
---|
163 | ); |
---|
164 | |
---|
165 | /** @brief Thread queue Dequeue priority |
---|
166 | * |
---|
167 | * This function returns a pointer to the highest priority |
---|
168 | * thread waiting on the_thread_queue. If no threads are waiting |
---|
169 | * on the_thread_queue, then NULL is returned. |
---|
170 | */ |
---|
171 | Thread_Control *_Thread_queue_Dequeue_priority( |
---|
172 | Thread_queue_Control *the_thread_queue |
---|
173 | ); |
---|
174 | |
---|
175 | /** @brief Thread queue Enqueue priority |
---|
176 | * |
---|
177 | * This routine enqueues the currently executing thread on |
---|
178 | * the_thread_queue with an optional timeout using the |
---|
179 | * priority discipline. |
---|
180 | */ |
---|
181 | Thread_blocking_operation_States _Thread_queue_Enqueue_priority ( |
---|
182 | Thread_queue_Control *the_thread_queue, |
---|
183 | Thread_Control *the_thread, |
---|
184 | ISR_Level *level_p |
---|
185 | ); |
---|
186 | |
---|
187 | /** @brief Thread queue Extract priority Helper |
---|
188 | * |
---|
189 | * This routine removes the_thread from the_thread_queue |
---|
190 | * and cancels any timeouts associated with this blocking. |
---|
191 | */ |
---|
192 | void _Thread_queue_Extract_priority_helper( |
---|
193 | Thread_queue_Control *the_thread_queue, |
---|
194 | Thread_Control *the_thread, |
---|
195 | boolean requeuing |
---|
196 | ); |
---|
197 | |
---|
198 | /** |
---|
199 | * @brief Thread queue Extract priority |
---|
200 | * |
---|
201 | * This macro wraps the underlying call and hides the requeuing argument. |
---|
202 | */ |
---|
203 | |
---|
204 | #define _Thread_queue_Extract_priority( _the_thread_queue, _the_thread ) \ |
---|
205 | _Thread_queue_Extract_priority_helper( _the_thread_queue, _the_thread, FALSE ) |
---|
206 | |
---|
207 | |
---|
208 | /** @brief Thread queue First priority |
---|
209 | * |
---|
210 | * This function returns a pointer to the "first" thread |
---|
211 | * on the_thread_queue. The "first" thread is the highest |
---|
212 | * priority thread waiting on the_thread_queue. |
---|
213 | */ |
---|
214 | Thread_Control *_Thread_queue_First_priority( |
---|
215 | Thread_queue_Control *the_thread_queue |
---|
216 | ); |
---|
217 | |
---|
218 | /** @brief Thread queue Dequeue FIFO |
---|
219 | * |
---|
220 | * This function returns a pointer to the thread which has |
---|
221 | * been waiting the longest on the_thread_queue. If no |
---|
222 | * threads are waiting on the_thread_queue, then NULL is returned. |
---|
223 | */ |
---|
224 | Thread_Control *_Thread_queue_Dequeue_fifo( |
---|
225 | Thread_queue_Control *the_thread_queue |
---|
226 | ); |
---|
227 | |
---|
228 | /** @brief Thread queue Enqueue FIFO |
---|
229 | * |
---|
230 | * This routine enqueues the currently executing thread on |
---|
231 | * the_thread_queue with an optional timeout using the |
---|
232 | * FIFO discipline. |
---|
233 | */ |
---|
234 | Thread_blocking_operation_States _Thread_queue_Enqueue_fifo ( |
---|
235 | Thread_queue_Control *the_thread_queue, |
---|
236 | Thread_Control *the_thread, |
---|
237 | ISR_Level *level_p |
---|
238 | ); |
---|
239 | |
---|
240 | /** @brief Thread queue Extract FIFO |
---|
241 | * |
---|
242 | * This routine removes the_thread from the_thread_queue |
---|
243 | * and cancels any timeouts associated with this blocking. |
---|
244 | */ |
---|
245 | void _Thread_queue_Extract_fifo( |
---|
246 | Thread_queue_Control *the_thread_queue, |
---|
247 | Thread_Control *the_thread |
---|
248 | ); |
---|
249 | |
---|
250 | /** @brief Thread queue First FIFO |
---|
251 | * |
---|
252 | * This function returns a pointer to the "first" thread |
---|
253 | * on the_thread_queue. The first thread is the thread |
---|
254 | * which has been waiting longest on the_thread_queue. |
---|
255 | */ |
---|
256 | Thread_Control *_Thread_queue_First_fifo( |
---|
257 | Thread_queue_Control *the_thread_queue |
---|
258 | ); |
---|
259 | |
---|
260 | /** @brief Thread queue timeout |
---|
261 | * |
---|
262 | * This routine is invoked when a task's request has not |
---|
263 | * been satisfied after the timeout interval specified to |
---|
264 | * enqueue. The task represented by ID will be unblocked and |
---|
265 | * its status code will be set in it's control block to indicate |
---|
266 | * that a timeout has occurred. |
---|
267 | */ |
---|
268 | void _Thread_queue_Timeout ( |
---|
269 | Objects_Id id, |
---|
270 | void *ignored |
---|
271 | ); |
---|
272 | |
---|
273 | |
---|
274 | #ifndef __RTEMS_APPLICATION__ |
---|
275 | #include <rtems/score/threadq.inl> |
---|
276 | #endif |
---|
277 | |
---|
278 | #ifdef __cplusplus |
---|
279 | } |
---|
280 | #endif |
---|
281 | |
---|
282 | /**@}*/ |
---|
283 | |
---|
284 | #endif |
---|
285 | /* end of include file */ |
---|