source: rtems/cpukit/score/include/rtems/score/threadqimpl.h @ a112364

4.115
Last change on this file since a112364 was a112364, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 15:30:26

score: Create threadq implementation header

Move implementation specific parts of tqdata.h, threadq.h and
threadq.inl into new header file threadqimpl.h. The threadq.h contains
now only the application visible API.

Delete tqdata.h.

  • Property mode set to 100644
File size: 12.3 KB
Line 
1/**
2 *  @file  rtems/score/threadq.h
3 *
4 *  Constants and Structures Associated with the Manipulation of Objects
5 *
6 *  This include file contains all the constants and structures associated
7 *  with the manipulation of objects.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2009.
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.com/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_THREADQIMPL_H
20#define _RTEMS_SCORE_THREADQIMPL_H
21
22#include <rtems/score/threadq.h>
23#include <rtems/score/thread.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/**
30 *  @addtogroup ScoreThreadQueue
31 */
32/**@{*/
33
34/**
35 *  Constant for indefinite wait.
36 */
37#define THREAD_QUEUE_WAIT_FOREVER  WATCHDOG_NO_TIMEOUT
38
39/**
40 *  This is one of the constants used to manage the priority queues.
41 *  @ref TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS for more details.
42 */
43#define TASK_QUEUE_DATA_PRIORITIES_PER_HEADER      64
44
45/**
46 *  This is one of the constants used to manage the priority queues.
47 *  @ref TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS for more details.
48 */
49#define TASK_QUEUE_DATA_REVERSE_SEARCH_MASK        0x20
50
51/**
52 *  The following type defines the callout used when a remote task
53 *  is extracted from a local thread queue.
54 */
55typedef void ( *Thread_queue_Flush_callout )(
56                  Thread_Control *
57             );
58
59/**
60 *  The following type defines the callout used for timeout processing
61 *  methods.
62 */
63typedef void ( *Thread_queue_Timeout_callout )(
64                 Objects_Id,
65                 void *
66             );
67
68/**
69 *  @brief Gets a pointer to a thread waiting on the_thread_queue.
70 *
71 *  This function returns a pointer to a thread waiting on
72 *  the_thread_queue.  The selection of this thread is based on
73 *  the discipline of the_thread_queue.  If no threads are waiting
74 *  on the_thread_queue, then NULL is returned.
75 */
76Thread_Control *_Thread_queue_Dequeue(
77  Thread_queue_Control *the_thread_queue
78);
79
80/**
81 *  @brief Enqueues the currently executing thread on the_thread_queue.
82 *
83 *  This routine enqueues the currently executing thread on
84 *  the_thread_queue with an optional timeout.
85 */
86#define _Thread_queue_Enqueue( _the_thread_queue, _timeout ) \
87  _Thread_queue_Enqueue_with_handler( \
88    _the_thread_queue, \
89    _timeout, \
90    _Thread_queue_Timeout )
91
92/**
93 *  @brief Blocks a thread and places it on a thread.
94 *
95 *  This routine blocks a thread, places it on a thread, and optionally
96 *  starts a timeout timer.
97 *
98 *  @param[in] the_thread_queue pointer to threadq
99 *  @param[in] timeout interval to wait
100 *
101 *  - INTERRUPT LATENCY:
102 *    + single case
103 */
104void _Thread_queue_Enqueue_with_handler(
105  Thread_queue_Control*        the_thread_queue,
106  Watchdog_Interval            timeout,
107  Thread_queue_Timeout_callout handler
108);
109
110/**
111 *  @brief Invoked when a thread changes priority and is blocked.
112 *
113 *  This routine is invoked when a thread changes priority and is
114 *  blocked on a thread queue.  If the queue is priority ordered,
115 *  the_thread is removed from the_thread_queue and reinserted using
116 *  its new priority.  This method has no impact on the state of the_thread
117 *  or of any timeouts associated with this blocking.
118 *
119 *  @param[in] the_thread_queue pointer to a threadq header
120 *  @param[in] the_thread pointer to a thread control block
121 */
122void _Thread_queue_Requeue(
123  Thread_queue_Control *the_thread_queue,
124  Thread_Control       *the_thread
125);
126
127/**
128 *  @brief Extracts thread from thread queue.
129 *
130 *  This routine removes @a the_thread from @a the_thread_queue
131 *  and cancels any timeouts associated with this blocking.
132 *
133 *  @param[in] the_thread_queue is the pointer to the ThreadQ header
134 *  @param[in] the_thread is the pointer to a thread control block that is to be removed
135 */
136void _Thread_queue_Extract(
137  Thread_queue_Control *the_thread_queue,
138  Thread_Control       *the_thread
139);
140
141/**
142 *  @brief Extracts the_thread from the_thread_queue.
143 *
144 *  This routine extracts the_thread from the_thread_queue
145 *  and ensures that if there is a proxy for this task on
146 *  another node, it is also dealt with.
147 */
148bool _Thread_queue_Extract_with_proxy(
149  Thread_Control       *the_thread
150);
151
152/**
153 *  @brief Gets a pointer to the "first" thread on the_thread_queue.
154 *
155 *  This function returns a pointer to the "first" thread
156 *  on the_thread_queue.  The "first" thread is selected
157 *  based on the discipline of the_thread_queue.
158 *
159 *  @param[in] the_thread_queue pointer to thread queue
160 *
161 *  @retval first thread or NULL
162 */
163Thread_Control *_Thread_queue_First(
164  Thread_queue_Control *the_thread_queue
165);
166
167/**
168 *  @brief Unblocks all threads blocked on the_thread_queue.
169 *
170 *  This routine unblocks all threads blocked on the_thread_queue
171 *  and cancels any associated timeouts.
172 *
173 *  @param[in] the_thread_queue is the pointer to a threadq header
174 *  @param[in] remote_extract_callout points to a method to invoke to
175 *             invoke when a remote thread is unblocked
176 *  @param[in] status is the status which will be returned to
177 *             all unblocked threads
178 */
179void _Thread_queue_Flush(
180  Thread_queue_Control       *the_thread_queue,
181  Thread_queue_Flush_callout  remote_extract_callout,
182  uint32_t                    status
183);
184
185/**
186 *  @brief Initialize the_thread_queue.
187 *
188 *  This routine initializes the_thread_queue based on the
189 *  discipline indicated in attribute_set.  The state set on
190 *  threads which block on the_thread_queue is state.
191 *
192 *  @param[in] the_thread_queue is the pointer to a threadq header
193 *  @param[in] the_discipline is the queueing discipline
194 *  @param[in] state is the state of waiting threads
195 *  @param[in] timeout_status is the return on a timeout
196 */
197void _Thread_queue_Initialize(
198  Thread_queue_Control         *the_thread_queue,
199  Thread_queue_Disciplines      the_discipline,
200  States_Control                state,
201  uint32_t                      timeout_status
202);
203
204/**
205 *  @brief Removes a thread from the specified PRIORITY based
206 *  threadq, unblocks it, and cancels its timeout timer.
207 *
208 *  This routine removes a thread from the specified PRIORITY based
209 *  threadq, unblocks it, and cancels its timeout timer.
210 *
211 *  - INTERRUPT LATENCY:
212 *    + single case
213 *
214 * @param[in] the_thread_queue is a pointer to a thread queue
215 *
216 * @retval thread dequeued
217 * @retval NULL if no thread are waiting on the_thread_queue
218 */
219Thread_Control *_Thread_queue_Dequeue_priority(
220  Thread_queue_Control *the_thread_queue
221);
222
223/**
224 *  @brief Enqueues the currently executing thread on the_thread_queue.
225 *
226 *  This routine enqueues the currently executing thread on
227 *  the_thread_queue with an optional timeout using the
228 *  priority discipline.
229 *
230 *  @param[in] the_thread_queue is the pointer to threadq
231 *  @param[in] the_thread is the thread to insert
232 *  @param[in] level_p is a pointer to an interrupt level to be returned
233 *
234 *  @retval This methods returns an indication of the blocking state as
235 *          well as filling in *@ level_p with the previous interrupt level.
236 *
237 *  - INTERRUPT LATENCY:
238 *    + forward less than
239 *    + forward equal
240 */
241Thread_blocking_operation_States _Thread_queue_Enqueue_priority (
242  Thread_queue_Control *the_thread_queue,
243  Thread_Control       *the_thread,
244  ISR_Level            *level_p
245);
246
247/**
248 *  @brief Removes the_thread and cancels related timeouts.
249 *
250 *  This routine removes the_thread from the_thread_queue
251 *  and cancels any timeouts associated with this blocking.
252 *  @param[in] the_thread_queue pointer to a threadq header
253 *  @param[in] the_thread pointer to a thread control block
254 *  @param[in] requeuing true if requeuing and should not alter
255 *         timeout or state
256 *  - INTERRUPT LATENCY:
257 *    + EXTRACT_PRIORITY
258 */
259void _Thread_queue_Extract_priority_helper(
260  Thread_queue_Control *the_thread_queue,
261  Thread_Control       *the_thread,
262  bool                  requeuing
263);
264
265/**
266 *  @brief Wraps the underlying call and hides the requeuing argument.
267 *
268 * This macro wraps the underlying call and hides the requeuing argument.
269 */
270
271#define _Thread_queue_Extract_priority( _the_thread_queue, _the_thread ) \
272  _Thread_queue_Extract_priority_helper( _the_thread_queue, _the_thread, false )
273/**
274 *  @brief Get highest priority thread on the_thread_queue.
275 *
276 *  This function returns a pointer to the "first" thread
277 *  on @a the_thread_queue.  The "first" thread is the highest
278 *  priority thread waiting on @a the_thread_queue.
279 *
280 *  @param[in] the_thread_queue is the pointer to the thread queue
281 *  @retval first thread or NULL
282 */
283Thread_Control *_Thread_queue_First_priority(
284  Thread_queue_Control *the_thread_queue
285);
286
287/**
288 *  @brief Gets a pointer to the thread which has been waiting the longest.
289 *
290 *  This function returns a pointer to the thread which has
291 *  been waiting the longest on  the_thread_queue.  If no
292 *  threads are waiting on the_thread_queue, then NULL is returned.
293 *
294 *  @param[in] the_thread_queue is the pointer to threadq
295 *
296 *  @retval thread dequeued or NULL
297 *
298 *  - INTERRUPT LATENCY:
299 *    + check sync
300 *    + FIFO
301 */
302Thread_Control *_Thread_queue_Dequeue_fifo(
303  Thread_queue_Control *the_thread_queue
304);
305
306/**
307 *  @brief Enqueues the currently executing thread on the_thread_queue.
308 *
309 *  This routine enqueues the currently executing thread on
310 *  the_thread_queue with an optional timeout using the
311 *  FIFO discipline.
312 *
313 *    @param[in] the_thread_queue pointer to threadq
314 *    @param[in] the_thread pointer to the thread to block
315 *    @param[in] level_p interrupt level in case the operation blocks actually
316 *
317 *  - INTERRUPT LATENCY:
318 *    + single case
319 */
320Thread_blocking_operation_States _Thread_queue_Enqueue_fifo (
321  Thread_queue_Control *the_thread_queue,
322  Thread_Control       *the_thread,
323  ISR_Level            *level_p
324);
325
326/**
327 *  @brief Removes the_thread from the_thread_queue and cancels any timeouts.
328 *
329 *  This routine removes the_thread from the_thread_queue
330 *  and cancels any timeouts associated with this blocking.
331 */
332void _Thread_queue_Extract_fifo(
333  Thread_queue_Control *the_thread_queue,
334  Thread_Control       *the_thread
335);
336
337/**
338 *  @brief Gets a pointer to the "first" thread on the_thread_queue.
339 *
340 *  This function returns a pointer to the "first" thread
341 *  on the_thread_queue.  The first thread is the thread
342 *  which has been waiting longest on the_thread_queue.
343 *
344 *  @param[in] the_thread_queue is the pointer to threadq
345 *
346 *  @retval first thread or NULL
347 */
348Thread_Control *_Thread_queue_First_fifo(
349  Thread_queue_Control *the_thread_queue
350);
351
352/**
353 *  @brief Thread queue timeout.
354 *
355 *  This routine is invoked when a task's request has not
356 *  been satisfied after the timeout interval specified to
357 *  enqueue.  The task represented by ID will be unblocked and
358 *  its status code will be set in it's control block to indicate
359 *  that a timeout has occurred.
360 *
361 *  @param[in] id thread id
362 */
363void _Thread_queue_Timeout (
364  Objects_Id  id,
365  void       *ignored
366);
367
368/**
369 *  @brief Process thread queue timeout.
370 *
371 * This is a shared helper routine which makes it easier to have multiple
372 * object class specific timeout routines.
373 *
374 * @param[in] the_thread is the thread to extract
375 *
376 * @note This method assumes thread dispatching is disabled
377 *       and is expected to be called via the processing of
378 *       a clock tick.
379 */
380void _Thread_queue_Process_timeout(
381  Thread_Control *the_thread
382);
383
384/**
385 * This function returns the index of the priority chain on which
386 * a thread of the_priority should be placed.
387 */
388
389RTEMS_INLINE_ROUTINE uint32_t   _Thread_queue_Header_number (
390  Priority_Control the_priority
391)
392{
393  return (the_priority / TASK_QUEUE_DATA_PRIORITIES_PER_HEADER);
394}
395
396/**
397 * This function returns true if the_priority indicates that the
398 * enqueue search should start at the front of this priority
399 * group chain, and false if the search should start at the rear.
400 */
401
402RTEMS_INLINE_ROUTINE bool _Thread_queue_Is_reverse_search (
403  Priority_Control the_priority
404)
405{
406  return ( the_priority & TASK_QUEUE_DATA_REVERSE_SEARCH_MASK );
407}
408
409/**
410 * This routine is invoked to indicate that the specified thread queue is
411 * entering a critical section.
412 */
413
414RTEMS_INLINE_ROUTINE void _Thread_queue_Enter_critical_section (
415  Thread_queue_Control *the_thread_queue
416)
417{
418  the_thread_queue->sync_state = THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
419}
420
421/**@}*/
422
423#ifdef __cplusplus
424}
425#endif
426
427#endif
428/* end of include file */
Note: See TracBrowser for help on using the repository browser.