[20f02c6] | 1 | /** |
---|
[11874561] | 2 | * @file rtems/score/threadq.h |
---|
[ac7d5ef0] | 3 | * |
---|
| 4 | * This include file contains all the constants and structures associated |
---|
| 5 | * with the manipulation of objects. |
---|
[baff4da] | 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[3168deaa] | 9 | * COPYRIGHT (c) 1989-2008. |
---|
[ac7d5ef0] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
[98e4ebf5] | 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[dd687d97] | 14 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 15 | * |
---|
| 16 | * $Id$ |
---|
| 17 | */ |
---|
| 18 | |
---|
[092f142a] | 19 | #ifndef _RTEMS_SCORE_THREADQ_H |
---|
| 20 | #define _RTEMS_SCORE_THREADQ_H |
---|
[ac7d5ef0] | 21 | |
---|
[baff4da] | 22 | /** |
---|
| 23 | * @defgroup ScoreThreadQ Thread Queue Handler |
---|
| 24 | * |
---|
[6a07436] | 25 | * This handler encapsulates functionality related to managing sets of threads |
---|
| 26 | * blocked waiting for resources. |
---|
[baff4da] | 27 | */ |
---|
| 28 | /**@{*/ |
---|
| 29 | |
---|
[5e9b32b] | 30 | #include <rtems/score/tqdata.h> |
---|
[ac7d5ef0] | 31 | |
---|
[5e9b32b] | 32 | #include <rtems/score/object.h> |
---|
| 33 | #include <rtems/score/thread.h> |
---|
| 34 | #include <rtems/score/watchdog.h> |
---|
| 35 | |
---|
[45ef86e1] | 36 | #ifdef __cplusplus |
---|
| 37 | extern "C" { |
---|
| 38 | #endif |
---|
| 39 | |
---|
[baff4da] | 40 | /** |
---|
[5e9b32b] | 41 | * Constant for indefinite wait. |
---|
| 42 | */ |
---|
| 43 | #define THREAD_QUEUE_WAIT_FOREVER WATCHDOG_NO_TIMEOUT |
---|
[ac7d5ef0] | 44 | |
---|
[baff4da] | 45 | /** |
---|
[ac7d5ef0] | 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 )( |
---|
[047d67a] | 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 * |
---|
[ac7d5ef0] | 61 | ); |
---|
| 62 | |
---|
[baff4da] | 63 | /** @brief Thread queue Dequeue |
---|
[ac7d5ef0] | 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 | |
---|
[047d67a] | 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 ) |
---|
[20f02c6] | 84 | |
---|
[047d67a] | 85 | |
---|
[baff4da] | 86 | /** @brief Thread queue Enqueue |
---|
[ac7d5ef0] | 87 | * |
---|
| 88 | * This routine enqueues the currently executing thread on |
---|
| 89 | * the_thread_queue with an optional timeout. |
---|
| 90 | */ |
---|
[047d67a] | 91 | void _Thread_queue_Enqueue_with_handler( |
---|
| 92 | Thread_queue_Control* the_thread_queue, |
---|
| 93 | Watchdog_Interval timeout, |
---|
| 94 | Thread_queue_Timeout_callout handler |
---|
[ac7d5ef0] | 95 | ); |
---|
| 96 | |
---|
[96d0b64] | 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 | |
---|
[baff4da] | 111 | /** @brief Thread queue Extract |
---|
[ac7d5ef0] | 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 | |
---|
[baff4da] | 121 | /** @brief Thread queue Extract with proxy |
---|
[7f6a24ab] | 122 | * |
---|
| 123 | * This routine extracts the_thread from the_thread_queue |
---|
[a0ed4ed] | 124 | * and ensures that if there is a proxy for this task on |
---|
[7f6a24ab] | 125 | * another node, it is also dealt with. |
---|
| 126 | */ |
---|
[484a769] | 127 | bool _Thread_queue_Extract_with_proxy( |
---|
[7f6a24ab] | 128 | Thread_Control *the_thread |
---|
| 129 | ); |
---|
| 130 | |
---|
[baff4da] | 131 | /** @brief Thread queue First |
---|
[ac7d5ef0] | 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 | |
---|
[baff4da] | 141 | /** @brief Thread queue Flush |
---|
[ac7d5ef0] | 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, |
---|
[3a4ae6c] | 148 | Thread_queue_Flush_callout remote_extract_callout, |
---|
[d6154c7] | 149 | uint32_t status |
---|
[ac7d5ef0] | 150 | ); |
---|
| 151 | |
---|
[baff4da] | 152 | /** @brief Thread queue Initialize |
---|
[ac7d5ef0] | 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( |
---|
[7f6a24ab] | 159 | Thread_queue_Control *the_thread_queue, |
---|
| 160 | Thread_queue_Disciplines the_discipline, |
---|
| 161 | States_Control state, |
---|
[d6154c7] | 162 | uint32_t timeout_status |
---|
[ac7d5ef0] | 163 | ); |
---|
| 164 | |
---|
[baff4da] | 165 | /** @brief Thread queue Dequeue priority |
---|
[ac7d5ef0] | 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 | |
---|
[baff4da] | 175 | /** @brief Thread queue Enqueue priority |
---|
[ac7d5ef0] | 176 | * |
---|
| 177 | * This routine enqueues the currently executing thread on |
---|
| 178 | * the_thread_queue with an optional timeout using the |
---|
| 179 | * priority discipline. |
---|
| 180 | */ |
---|
[3168deaa] | 181 | Thread_blocking_operation_States _Thread_queue_Enqueue_priority ( |
---|
[ac7d5ef0] | 182 | Thread_queue_Control *the_thread_queue, |
---|
[3168deaa] | 183 | Thread_Control *the_thread, |
---|
| 184 | ISR_Level *level_p |
---|
[ac7d5ef0] | 185 | ); |
---|
| 186 | |
---|
[96d0b64] | 187 | /** @brief Thread queue Extract priority Helper |
---|
[ac7d5ef0] | 188 | * |
---|
| 189 | * This routine removes the_thread from the_thread_queue |
---|
| 190 | * and cancels any timeouts associated with this blocking. |
---|
| 191 | */ |
---|
[96d0b64] | 192 | void _Thread_queue_Extract_priority_helper( |
---|
[ac7d5ef0] | 193 | Thread_queue_Control *the_thread_queue, |
---|
[96d0b64] | 194 | Thread_Control *the_thread, |
---|
[20f02c6] | 195 | bool requeuing |
---|
[ac7d5ef0] | 196 | ); |
---|
| 197 | |
---|
[96d0b64] | 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 ) \ |
---|
[c6b3719] | 205 | _Thread_queue_Extract_priority_helper( _the_thread_queue, _the_thread, false ) |
---|
[96d0b64] | 206 | |
---|
| 207 | |
---|
[baff4da] | 208 | /** @brief Thread queue First priority |
---|
[ac7d5ef0] | 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 | |
---|
[baff4da] | 218 | /** @brief Thread queue Dequeue FIFO |
---|
[ac7d5ef0] | 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 | |
---|
[baff4da] | 228 | /** @brief Thread queue Enqueue FIFO |
---|
[ac7d5ef0] | 229 | * |
---|
| 230 | * This routine enqueues the currently executing thread on |
---|
| 231 | * the_thread_queue with an optional timeout using the |
---|
[3a4ae6c] | 232 | * FIFO discipline. |
---|
[ac7d5ef0] | 233 | */ |
---|
[3168deaa] | 234 | Thread_blocking_operation_States _Thread_queue_Enqueue_fifo ( |
---|
[ac7d5ef0] | 235 | Thread_queue_Control *the_thread_queue, |
---|
[3168deaa] | 236 | Thread_Control *the_thread, |
---|
| 237 | ISR_Level *level_p |
---|
[ac7d5ef0] | 238 | ); |
---|
| 239 | |
---|
[baff4da] | 240 | /** @brief Thread queue Extract FIFO |
---|
[ac7d5ef0] | 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 | |
---|
[baff4da] | 250 | /** @brief Thread queue First FIFO |
---|
[ac7d5ef0] | 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 | |
---|
[baff4da] | 260 | /** @brief Thread queue timeout |
---|
[ac7d5ef0] | 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 | |
---|
[c57f26bd] | 273 | /** |
---|
| 274 | * @brief Process Thread Queue Timeout |
---|
| 275 | * |
---|
[20f02c6] | 276 | * This is a shared helper routine which makes it easier to have multiple |
---|
[c57f26bd] | 277 | * object class specific timeout routines. |
---|
| 278 | * |
---|
| 279 | * @param[in] the_thread is the thread to extract |
---|
| 280 | * |
---|
| 281 | * @note This method assumes thread dispatching is disabled |
---|
| 282 | * and is expected to be called via the processing of |
---|
| 283 | * a clock tick. |
---|
| 284 | */ |
---|
| 285 | void _Thread_queue_Process_timeout( |
---|
| 286 | Thread_Control *the_thread |
---|
| 287 | ); |
---|
[047d67a] | 288 | |
---|
| 289 | #ifndef __RTEMS_APPLICATION__ |
---|
| 290 | #include <rtems/score/threadq.inl> |
---|
| 291 | #endif |
---|
| 292 | |
---|
[ac7d5ef0] | 293 | #ifdef __cplusplus |
---|
| 294 | } |
---|
| 295 | #endif |
---|
| 296 | |
---|
[baff4da] | 297 | /**@}*/ |
---|
| 298 | |
---|
[ac7d5ef0] | 299 | #endif |
---|
| 300 | /* end of include file */ |
---|