[ac7d5ef0] | 1 | /* thread.h |
---|
| 2 | * |
---|
| 3 | * This include file contains all constants and structures associated |
---|
| 4 | * with the thread control block. |
---|
| 5 | * |
---|
[08311cc3] | 6 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
[98e4ebf5] | 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[dd687d97] | 11 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
[3a4ae6c] | 16 | #ifndef __THREAD_h |
---|
| 17 | #define __THREAD_h |
---|
[ac7d5ef0] | 18 | |
---|
| 19 | #ifdef __cplusplus |
---|
| 20 | extern "C" { |
---|
| 21 | #endif |
---|
| 22 | |
---|
[5e9b32b] | 23 | #include <rtems/score/context.h> |
---|
| 24 | #include <rtems/score/cpu.h> |
---|
[97e2729d] | 25 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[5e9b32b] | 26 | #include <rtems/score/mppkt.h> |
---|
[97e2729d] | 27 | #endif |
---|
[5e9b32b] | 28 | #include <rtems/score/object.h> |
---|
| 29 | #include <rtems/score/priority.h> |
---|
| 30 | #include <rtems/score/stack.h> |
---|
| 31 | #include <rtems/score/states.h> |
---|
| 32 | #include <rtems/score/tod.h> |
---|
| 33 | #include <rtems/score/tqdata.h> |
---|
| 34 | #include <rtems/score/watchdog.h> |
---|
[ac7d5ef0] | 35 | |
---|
| 36 | /* |
---|
[3a4ae6c] | 37 | * The following defines the "return type" of a thread. |
---|
[260b0c2] | 38 | * |
---|
| 39 | * NOTE: This cannot always be right. Some APIs have void |
---|
| 40 | * tasks/threads, others return pointers, others may |
---|
| 41 | * return a numeric value. Hopefully a pointer is |
---|
[d6154c7] | 42 | * always at least as big as an uint32_t . :) |
---|
[ac7d5ef0] | 43 | */ |
---|
| 44 | |
---|
[260b0c2] | 45 | typedef void *Thread; |
---|
[ac7d5ef0] | 46 | |
---|
| 47 | /* |
---|
[3a4ae6c] | 48 | * The following defines the ways in which the entry point for a |
---|
| 49 | * thread can be invoked. Basically, it can be passed any |
---|
[d6154c7] | 50 | * combination/permutation of a pointer and an uint32_t value. |
---|
[3a4ae6c] | 51 | * |
---|
| 52 | * NOTE: For now, we are ignoring the return type. |
---|
[ac7d5ef0] | 53 | */ |
---|
| 54 | |
---|
[3a4ae6c] | 55 | typedef enum { |
---|
| 56 | THREAD_START_NUMERIC, |
---|
| 57 | THREAD_START_POINTER, |
---|
| 58 | THREAD_START_BOTH_POINTER_FIRST, |
---|
| 59 | THREAD_START_BOTH_NUMERIC_FIRST |
---|
| 60 | } Thread_Start_types; |
---|
[ac7d5ef0] | 61 | |
---|
[0d051533] | 62 | typedef Thread ( *Thread_Entry )(); /* basic type */ |
---|
| 63 | |
---|
[d6154c7] | 64 | typedef Thread ( *Thread_Entry_numeric )( uint32_t ); |
---|
[0d051533] | 65 | typedef Thread ( *Thread_Entry_pointer )( void * ); |
---|
[d6154c7] | 66 | typedef Thread ( *Thread_Entry_both_pointer_first )( void *, uint32_t ); |
---|
| 67 | typedef Thread ( *Thread_Entry_both_numeric_first )( uint32_t , void * ); |
---|
[ac7d5ef0] | 68 | |
---|
[2f200c7] | 69 | /* |
---|
| 70 | * The following lists the algorithms used to manage the thread cpu budget. |
---|
| 71 | * |
---|
| 72 | * Reset Timeslice: At each context switch, reset the time quantum. |
---|
| 73 | * Exhaust Timeslice: Only reset the quantum once it is consumed. |
---|
| 74 | * Callout: Execute routine when budget is consumed. |
---|
| 75 | */ |
---|
| 76 | |
---|
| 77 | typedef enum { |
---|
| 78 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
| 79 | THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE, |
---|
| 80 | THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE, |
---|
| 81 | THREAD_CPU_BUDGET_ALGORITHM_CALLOUT |
---|
| 82 | } Thread_CPU_budget_algorithms; |
---|
| 83 | |
---|
| 84 | typedef struct Thread_Control_struct Thread_Control; |
---|
| 85 | |
---|
| 86 | typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * ); |
---|
| 87 | |
---|
[aad726e] | 88 | /* |
---|
| 89 | * Per task variable structure |
---|
| 90 | */ |
---|
| 91 | |
---|
| 92 | struct rtems_task_variable_tt; |
---|
| 93 | |
---|
| 94 | struct rtems_task_variable_tt { |
---|
| 95 | struct rtems_task_variable_tt *next; |
---|
[c941a98] | 96 | void **ptr; |
---|
[df49c60] | 97 | void *gval; |
---|
| 98 | void *tval; |
---|
[c941a98] | 99 | void (*dtor)(void *); |
---|
[aad726e] | 100 | }; |
---|
| 101 | |
---|
| 102 | typedef struct rtems_task_variable_tt rtems_task_variable_t; |
---|
| 103 | |
---|
[ac7d5ef0] | 104 | /* |
---|
| 105 | * The following structure contains the information which defines |
---|
| 106 | * the starting state of a thread. |
---|
| 107 | */ |
---|
| 108 | |
---|
| 109 | typedef struct { |
---|
| 110 | Thread_Entry entry_point; /* starting thread address */ |
---|
[7f6a24ab] | 111 | Thread_Start_types prototype; /* how task is invoked */ |
---|
| 112 | void *pointer_argument; /* pointer argument */ |
---|
[d6154c7] | 113 | uint32_t numeric_argument; /* numeric argument */ |
---|
[3a4ae6c] | 114 | /* initial execution modes */ |
---|
| 115 | boolean is_preemptible; |
---|
[2f200c7] | 116 | Thread_CPU_budget_algorithms budget_algorithm; |
---|
| 117 | Thread_CPU_budget_algorithm_callout budget_callout; |
---|
[d6154c7] | 118 | uint32_t isr_level; |
---|
[7f6a24ab] | 119 | Priority_Control initial_priority; /* initial priority */ |
---|
[98162c35] | 120 | boolean core_allocated_stack; |
---|
[ac7d5ef0] | 121 | Stack_Control Initial_stack; /* stack information */ |
---|
[47ca0d0a] | 122 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
[7f6a24ab] | 123 | void *fp_context; /* initial FP context area address */ |
---|
[17508d02] | 124 | #endif |
---|
[b6770d1] | 125 | void *stack; /* initial stack area address */ |
---|
[ac7d5ef0] | 126 | } Thread_Start_information; |
---|
| 127 | |
---|
| 128 | /* |
---|
| 129 | * The following structure contains the information necessary to manage |
---|
| 130 | * a thread which it is waiting for a resource. |
---|
| 131 | */ |
---|
| 132 | |
---|
[3a4ae6c] | 133 | #define THREAD_STATUS_PROXY_BLOCKING 0x1111111 |
---|
| 134 | |
---|
[ac7d5ef0] | 135 | typedef struct { |
---|
| 136 | Objects_Id id; /* waiting on this object */ |
---|
[d6154c7] | 137 | uint32_t count; /* "generic" fields to be used */ |
---|
[3a4ae6c] | 138 | void *return_argument; /* when blocking */ |
---|
| 139 | void *return_argument_1; |
---|
[d6154c7] | 140 | uint32_t option; |
---|
[3a4ae6c] | 141 | |
---|
| 142 | /* |
---|
| 143 | * NOTE: The following assumes that all API return codes can be |
---|
[d6154c7] | 144 | * treated as an uint32_t . |
---|
[3a4ae6c] | 145 | */ |
---|
[d6154c7] | 146 | uint32_t return_code; /* status for thread awakened */ |
---|
[3a4ae6c] | 147 | |
---|
[ac7d5ef0] | 148 | Chain_Control Block2n; /* 2 - n priority blocked chain */ |
---|
| 149 | Thread_queue_Control *queue; /* pointer to thread queue */ |
---|
| 150 | } Thread_Wait_information; |
---|
| 151 | |
---|
| 152 | /* |
---|
| 153 | * The following defines the control block used to manage |
---|
| 154 | * each thread proxy. |
---|
| 155 | * |
---|
| 156 | * NOTE: It is critical that proxies and threads have identical |
---|
| 157 | * memory images for the shared part. |
---|
| 158 | */ |
---|
| 159 | |
---|
| 160 | typedef struct { |
---|
| 161 | Objects_Control Object; |
---|
| 162 | States_Control current_state; |
---|
[7f6a24ab] | 163 | Priority_Control current_priority; |
---|
| 164 | Priority_Control real_priority; |
---|
[d6154c7] | 165 | uint32_t resource_count; |
---|
[ac7d5ef0] | 166 | Thread_Wait_information Wait; |
---|
| 167 | Watchdog_Control Timer; |
---|
[97e2729d] | 168 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 169 | MP_packet_Prefix *receive_packet; |
---|
[97e2729d] | 170 | #endif |
---|
[ac7d5ef0] | 171 | /****************** end of common block ********************/ |
---|
| 172 | Chain_Node Active; |
---|
| 173 | } Thread_Proxy_control; |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | /* |
---|
| 177 | * The following record defines the control block used |
---|
| 178 | * to manage each thread. |
---|
| 179 | * |
---|
| 180 | * NOTE: It is critical that proxies and threads have identical |
---|
| 181 | * memory images for the shared part. |
---|
| 182 | */ |
---|
| 183 | |
---|
[3a4ae6c] | 184 | typedef enum { |
---|
[5e9b32b] | 185 | THREAD_API_RTEMS, |
---|
[352c9b2] | 186 | THREAD_API_POSIX, |
---|
| 187 | THREAD_API_ITRON |
---|
[3a4ae6c] | 188 | } Thread_APIs; |
---|
[7f6a24ab] | 189 | |
---|
[3a4ae6c] | 190 | #define THREAD_API_FIRST THREAD_API_RTEMS |
---|
[352c9b2] | 191 | #define THREAD_API_LAST THREAD_API_ITRON |
---|
[7f6a24ab] | 192 | |
---|
[2f200c7] | 193 | struct Thread_Control_struct { |
---|
| 194 | Objects_Control Object; |
---|
| 195 | States_Control current_state; |
---|
| 196 | Priority_Control current_priority; |
---|
| 197 | Priority_Control real_priority; |
---|
[d6154c7] | 198 | uint32_t resource_count; |
---|
[2f200c7] | 199 | Thread_Wait_information Wait; |
---|
| 200 | Watchdog_Control Timer; |
---|
[97e2729d] | 201 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[2f200c7] | 202 | MP_packet_Prefix *receive_packet; |
---|
[97e2729d] | 203 | #endif |
---|
[ac7d5ef0] | 204 | /****************** end of common block ********************/ |
---|
[d6154c7] | 205 | uint32_t suspend_count; |
---|
[2f200c7] | 206 | boolean is_global; |
---|
| 207 | boolean do_post_task_switch_extension; |
---|
| 208 | |
---|
| 209 | boolean is_preemptible; |
---|
[847375f] | 210 | void *rtems_ada_self; |
---|
[d6154c7] | 211 | uint32_t cpu_time_budget; |
---|
[2f200c7] | 212 | Thread_CPU_budget_algorithms budget_algorithm; |
---|
| 213 | Thread_CPU_budget_algorithm_callout budget_callout; |
---|
| 214 | |
---|
[d6154c7] | 215 | uint32_t ticks_executed; |
---|
[2f200c7] | 216 | Chain_Control *ready; |
---|
| 217 | Priority_Information Priority_map; |
---|
| 218 | Thread_Start_information Start; |
---|
| 219 | Context_Control Registers; |
---|
[499d443] | 220 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
[2f200c7] | 221 | void *fp_context; |
---|
[17508d02] | 222 | #endif |
---|
[d36b3152] | 223 | struct _reent *libc_reent; |
---|
[2f200c7] | 224 | void *API_Extensions[ THREAD_API_LAST + 1 ]; |
---|
| 225 | void **extensions; |
---|
[aad726e] | 226 | rtems_task_variable_t *task_variables; |
---|
[2f200c7] | 227 | }; |
---|
[ac7d5ef0] | 228 | |
---|
[847375f] | 229 | /* |
---|
| 230 | * Self for the GNU Ada Run-Time |
---|
| 231 | */ |
---|
| 232 | |
---|
| 233 | SCORE_EXTERN void *rtems_ada_self; |
---|
| 234 | |
---|
[adf98bd] | 235 | /* |
---|
| 236 | * The following defines the information control block used to |
---|
| 237 | * manage this class of objects. |
---|
| 238 | */ |
---|
| 239 | |
---|
[c627b2a3] | 240 | SCORE_EXTERN Objects_Information _Thread_Internal_information; |
---|
[adf98bd] | 241 | |
---|
| 242 | /* |
---|
| 243 | * The following define the thread control pointers used to access |
---|
| 244 | * and manipulate the idle thread. |
---|
| 245 | */ |
---|
| 246 | |
---|
[c627b2a3] | 247 | SCORE_EXTERN Thread_Control *_Thread_Idle; |
---|
[adf98bd] | 248 | |
---|
[ac7d5ef0] | 249 | /* |
---|
[3a4ae6c] | 250 | * The following context area contains the context of the "thread" |
---|
| 251 | * which invoked the start multitasking routine. This context is |
---|
| 252 | * restored as the last action of the stop multitasking routine. Thus |
---|
| 253 | * control of the processor can be returned to the environment |
---|
| 254 | * which initiated the system. |
---|
[ac7d5ef0] | 255 | */ |
---|
[3a4ae6c] | 256 | |
---|
[c627b2a3] | 257 | SCORE_EXTERN Context_Control _Thread_BSP_context; |
---|
[3a4ae6c] | 258 | |
---|
[ac7d5ef0] | 259 | /* |
---|
| 260 | * The following declares the dispatch critical section nesting |
---|
| 261 | * counter which is used to prevent context switches at inopportune |
---|
| 262 | * moments. |
---|
| 263 | */ |
---|
| 264 | |
---|
[d6154c7] | 265 | SCORE_EXTERN volatile uint32_t _Thread_Dispatch_disable_level; |
---|
[ac7d5ef0] | 266 | |
---|
[1b17790c] | 267 | /* |
---|
| 268 | * If this is non-zero, then the post-task switch extension |
---|
| 269 | * is run regardless of the state of the per thread flag. |
---|
| 270 | */ |
---|
| 271 | |
---|
[d6154c7] | 272 | SCORE_EXTERN uint32_t _Thread_Do_post_task_switch_extension; |
---|
[1b17790c] | 273 | |
---|
[3a4ae6c] | 274 | /* |
---|
| 275 | * The following holds how many user extensions are in the system. This |
---|
| 276 | * is used to determine how many user extension data areas to allocate |
---|
| 277 | * per thread. |
---|
| 278 | */ |
---|
| 279 | |
---|
[d6154c7] | 280 | SCORE_EXTERN uint32_t _Thread_Maximum_extensions; |
---|
[3a4ae6c] | 281 | |
---|
[ac7d5ef0] | 282 | /* |
---|
[7aa4671] | 283 | * The following is used to manage the length of a timeslice quantum. |
---|
[ac7d5ef0] | 284 | */ |
---|
| 285 | |
---|
[d6154c7] | 286 | SCORE_EXTERN uint32_t _Thread_Ticks_per_timeslice; |
---|
[ac7d5ef0] | 287 | |
---|
| 288 | /* |
---|
| 289 | * The following points to the array of FIFOs used to manage the |
---|
| 290 | * set of ready threads. |
---|
| 291 | */ |
---|
| 292 | |
---|
[c627b2a3] | 293 | SCORE_EXTERN Chain_Control *_Thread_Ready_chain; |
---|
[ac7d5ef0] | 294 | |
---|
| 295 | /* |
---|
| 296 | * The following points to the thread which is currently executing. |
---|
| 297 | * This thread is implicitly manipulated by numerous directives. |
---|
| 298 | */ |
---|
| 299 | |
---|
[c627b2a3] | 300 | SCORE_EXTERN Thread_Control *_Thread_Executing; |
---|
[ac7d5ef0] | 301 | |
---|
| 302 | /* |
---|
| 303 | * The following points to the highest priority ready thread |
---|
[3a4ae6c] | 304 | * in the system. Unless the current thread is not preemptibl, |
---|
[ac7d5ef0] | 305 | * then this thread will be context switched to when the next |
---|
| 306 | * dispatch occurs. |
---|
| 307 | */ |
---|
| 308 | |
---|
[c627b2a3] | 309 | SCORE_EXTERN Thread_Control *_Thread_Heir; |
---|
[ac7d5ef0] | 310 | |
---|
| 311 | /* |
---|
| 312 | * The following points to the thread whose floating point |
---|
| 313 | * context is currently loaded. |
---|
| 314 | */ |
---|
| 315 | |
---|
[499d443] | 316 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
[c627b2a3] | 317 | SCORE_EXTERN Thread_Control *_Thread_Allocated_fp; |
---|
[17508d02] | 318 | #endif |
---|
[ac7d5ef0] | 319 | |
---|
[0df8293e] | 320 | /* |
---|
| 321 | * The C library re-enter-rant global pointer. Some C library implementations |
---|
| 322 | * such as newlib have a single global pointer that changed during a context |
---|
| 323 | * switch. The pointer points to that global pointer. The Thread control block |
---|
| 324 | * holds a pointer to the task specific data. |
---|
| 325 | */ |
---|
[d36b3152] | 326 | SCORE_EXTERN struct _reent **_Thread_libc_reent; |
---|
[0df8293e] | 327 | |
---|
[ac7d5ef0] | 328 | /* |
---|
| 329 | * _Thread_Handler_initialization |
---|
| 330 | * |
---|
| 331 | * DESCRIPTION: |
---|
| 332 | * |
---|
| 333 | * This routine performs the initialization necessary for this handler. |
---|
| 334 | */ |
---|
| 335 | |
---|
| 336 | void _Thread_Handler_initialization ( |
---|
[d6154c7] | 337 | uint32_t ticks_per_timeslice, |
---|
| 338 | uint32_t maximum_extensions, |
---|
| 339 | uint32_t maximum_proxies |
---|
[ac7d5ef0] | 340 | ); |
---|
| 341 | |
---|
[adf98bd] | 342 | /* |
---|
| 343 | * _Thread_Create_idle |
---|
| 344 | * |
---|
| 345 | * DESCRIPTION: |
---|
| 346 | * |
---|
| 347 | * This routine creates the idle thread. |
---|
| 348 | * |
---|
| 349 | * WARNING!! No thread should be created before this one. |
---|
| 350 | */ |
---|
| 351 | |
---|
| 352 | void _Thread_Create_idle( void ); |
---|
| 353 | |
---|
[ac7d5ef0] | 354 | /* |
---|
| 355 | * _Thread_Start_multitasking |
---|
| 356 | * |
---|
| 357 | * DESCRIPTION: |
---|
| 358 | * |
---|
| 359 | * This routine initiates multitasking. It is invoked only as |
---|
| 360 | * part of initialization and its invocation is the last act of |
---|
[3a4ae6c] | 361 | * the non-multitasking part of the system initialization. |
---|
[ac7d5ef0] | 362 | */ |
---|
| 363 | |
---|
[b2b52cbc] | 364 | void _Thread_Start_multitasking( void ); |
---|
[ac7d5ef0] | 365 | |
---|
| 366 | /* |
---|
| 367 | * _Thread_Dispatch |
---|
| 368 | * |
---|
| 369 | * DESCRIPTION: |
---|
| 370 | * |
---|
| 371 | * This routine is responsible for transferring control of the |
---|
| 372 | * processor from the executing thread to the heir thread. As part |
---|
| 373 | * of this process, it is responsible for the following actions: |
---|
| 374 | * |
---|
| 375 | * + saving the context of the executing thread |
---|
| 376 | * + restoring the context of the heir thread |
---|
| 377 | * + dispatching any signals for the resulting executing thread |
---|
| 378 | */ |
---|
| 379 | |
---|
| 380 | void _Thread_Dispatch( void ); |
---|
| 381 | |
---|
[1178b8c] | 382 | /* |
---|
| 383 | * _Thread_Stack_Allocate |
---|
| 384 | * |
---|
| 385 | * DESCRIPTION: |
---|
| 386 | * |
---|
| 387 | * Allocate the requested stack space for the thread. |
---|
| 388 | * return the actual size allocated after any adjustment |
---|
| 389 | * or return zero if the allocation failed. |
---|
| 390 | * Set the Start.stack field to the address of the stack |
---|
| 391 | * |
---|
| 392 | * NOTES: NONE |
---|
| 393 | * |
---|
| 394 | */ |
---|
| 395 | |
---|
[d6154c7] | 396 | uint32_t _Thread_Stack_Allocate( |
---|
[1178b8c] | 397 | Thread_Control *the_thread, |
---|
[d6154c7] | 398 | uint32_t stack_size |
---|
[1178b8c] | 399 | ); |
---|
| 400 | |
---|
| 401 | /* |
---|
| 402 | * _Thread_Stack_Free |
---|
| 403 | * |
---|
| 404 | * DESCRIPTION: |
---|
| 405 | * |
---|
| 406 | * Deallocate the Thread's stack. |
---|
| 407 | * NOTES: NONE |
---|
| 408 | * |
---|
| 409 | */ |
---|
| 410 | |
---|
| 411 | void _Thread_Stack_Free( |
---|
| 412 | Thread_Control *the_thread |
---|
| 413 | ); |
---|
| 414 | |
---|
[7f6a24ab] | 415 | /* |
---|
| 416 | * _Thread_Initialize |
---|
| 417 | * |
---|
| 418 | * DESCRIPTION: |
---|
| 419 | * |
---|
[f6d0821] | 420 | * This routine initializes the specified the thread. It allocates |
---|
| 421 | * all memory associated with this thread. It completes by adding |
---|
| 422 | * the thread to the local object table so operations on this |
---|
| 423 | * thread id are allowed. |
---|
[2f200c7] | 424 | * |
---|
| 425 | * NOTES: |
---|
| 426 | * |
---|
| 427 | * If stack_area is NULL, it is allocated from the workspace. |
---|
| 428 | * |
---|
| 429 | * If the stack is allocated from the workspace, then it is guaranteed to be |
---|
| 430 | * of at least minimum size. |
---|
[7f6a24ab] | 431 | */ |
---|
| 432 | |
---|
| 433 | boolean _Thread_Initialize( |
---|
[2f200c7] | 434 | Objects_Information *information, |
---|
| 435 | Thread_Control *the_thread, |
---|
| 436 | void *stack_area, |
---|
[d6154c7] | 437 | uint32_t stack_size, |
---|
[2f200c7] | 438 | boolean is_fp, |
---|
| 439 | Priority_Control priority, |
---|
| 440 | boolean is_preemptible, |
---|
| 441 | Thread_CPU_budget_algorithms budget_algorithm, |
---|
| 442 | Thread_CPU_budget_algorithm_callout budget_callout, |
---|
[d6154c7] | 443 | uint32_t isr_level, |
---|
[2f200c7] | 444 | Objects_Name name |
---|
[7f6a24ab] | 445 | ); |
---|
| 446 | |
---|
| 447 | /* |
---|
| 448 | * _Thread_Start |
---|
| 449 | * |
---|
| 450 | * DESCRIPTION: |
---|
| 451 | * |
---|
[f6d0821] | 452 | * This routine initializes the executable information for a thread |
---|
| 453 | * and makes it ready to execute. After this routine executes, the |
---|
| 454 | * thread competes with all other threads for CPU time. |
---|
[7f6a24ab] | 455 | */ |
---|
| 456 | |
---|
| 457 | boolean _Thread_Start( |
---|
| 458 | Thread_Control *the_thread, |
---|
| 459 | Thread_Start_types the_prototype, |
---|
| 460 | void *entry_point, |
---|
| 461 | void *pointer_argument, |
---|
[d6154c7] | 462 | uint32_t numeric_argument |
---|
[7f6a24ab] | 463 | ); |
---|
| 464 | |
---|
| 465 | /* |
---|
| 466 | * _Thread_Restart |
---|
| 467 | * |
---|
| 468 | * DESCRIPTION: |
---|
| 469 | * |
---|
[f6d0821] | 470 | * This support routine restarts the specified task in a way that the |
---|
| 471 | * next time this thread executes, it will begin execution at its |
---|
| 472 | * original starting point. |
---|
[7f6a24ab] | 473 | */ |
---|
| 474 | |
---|
| 475 | /* XXX multiple task arg profiles */ |
---|
| 476 | |
---|
| 477 | boolean _Thread_Restart( |
---|
| 478 | Thread_Control *the_thread, |
---|
| 479 | void *pointer_argument, |
---|
[d6154c7] | 480 | uint32_t numeric_argument |
---|
[7f6a24ab] | 481 | ); |
---|
| 482 | |
---|
[f6d0821] | 483 | /* |
---|
| 484 | * _Thread_Reset |
---|
| 485 | * |
---|
| 486 | * DESCRIPTION: |
---|
| 487 | * |
---|
| 488 | * This routine resets a thread to its initial state but does |
---|
| 489 | * not restart it. |
---|
| 490 | */ |
---|
| 491 | |
---|
| 492 | void _Thread_Reset( |
---|
| 493 | Thread_Control *the_thread, |
---|
| 494 | void *pointer_argument, |
---|
[d6154c7] | 495 | uint32_t numeric_argument |
---|
[f6d0821] | 496 | ); |
---|
| 497 | |
---|
[7f6a24ab] | 498 | /* |
---|
| 499 | * _Thread_Close |
---|
| 500 | * |
---|
| 501 | * DESCRIPTION: |
---|
| 502 | * |
---|
[f6d0821] | 503 | * This routine frees all memory associated with the specified |
---|
| 504 | * thread and removes it from the local object table so no further |
---|
| 505 | * operations on this thread are allowed. |
---|
[7f6a24ab] | 506 | */ |
---|
| 507 | |
---|
| 508 | void _Thread_Close( |
---|
| 509 | Objects_Information *information, |
---|
| 510 | Thread_Control *the_thread |
---|
| 511 | ); |
---|
| 512 | |
---|
[ac7d5ef0] | 513 | /* |
---|
| 514 | * _Thread_Ready |
---|
| 515 | * |
---|
| 516 | * DESCRIPTION: |
---|
| 517 | * |
---|
| 518 | * This routine removes any set states for the_thread. It performs |
---|
| 519 | * any necessary scheduling operations including the selection of |
---|
| 520 | * a new heir thread. |
---|
| 521 | */ |
---|
| 522 | |
---|
| 523 | void _Thread_Ready( |
---|
| 524 | Thread_Control *the_thread |
---|
| 525 | ); |
---|
| 526 | |
---|
| 527 | /* |
---|
| 528 | * _Thread_Clear_state |
---|
| 529 | * |
---|
| 530 | * DESCRIPTION: |
---|
| 531 | * |
---|
| 532 | * This routine clears the indicated STATES for the_thread. It performs |
---|
| 533 | * any necessary scheduling operations including the selection of |
---|
| 534 | * a new heir thread. |
---|
| 535 | */ |
---|
| 536 | |
---|
| 537 | void _Thread_Clear_state( |
---|
| 538 | Thread_Control *the_thread, |
---|
| 539 | States_Control state |
---|
| 540 | ); |
---|
| 541 | |
---|
| 542 | /* |
---|
| 543 | * _Thread_Set_state |
---|
| 544 | * |
---|
| 545 | * DESCRIPTION: |
---|
| 546 | * |
---|
| 547 | * This routine sets the indicated states for the_thread. It performs |
---|
| 548 | * any necessary scheduling operations including the selection of |
---|
| 549 | * a new heir thread. |
---|
| 550 | * |
---|
| 551 | */ |
---|
| 552 | |
---|
| 553 | void _Thread_Set_state( |
---|
| 554 | Thread_Control *the_thread, |
---|
| 555 | States_Control state |
---|
| 556 | ); |
---|
| 557 | |
---|
| 558 | /* |
---|
| 559 | * _Thread_Set_transient |
---|
| 560 | * |
---|
| 561 | * DESCRIPTION: |
---|
| 562 | * |
---|
| 563 | * This routine sets the TRANSIENT state for the_thread. It performs |
---|
| 564 | * any necessary scheduling operations including the selection of |
---|
| 565 | * a new heir thread. |
---|
| 566 | */ |
---|
| 567 | |
---|
| 568 | void _Thread_Set_transient( |
---|
| 569 | Thread_Control *the_thread |
---|
| 570 | ); |
---|
| 571 | |
---|
| 572 | /* |
---|
| 573 | * _Thread_Reset_timeslice |
---|
| 574 | * |
---|
| 575 | * DESCRIPTION: |
---|
| 576 | * |
---|
| 577 | * This routine is invoked upon expiration of the currently |
---|
| 578 | * executing thread's timeslice. If no other thread's are ready |
---|
| 579 | * at the priority of the currently executing thread, then the |
---|
| 580 | * executing thread's timeslice is reset. Otherwise, the |
---|
| 581 | * currently executing thread is placed at the rear of the |
---|
[3a4ae6c] | 582 | * FIFO for this priority and a new heir is selected. |
---|
[ac7d5ef0] | 583 | */ |
---|
| 584 | |
---|
| 585 | void _Thread_Reset_timeslice( void ); |
---|
| 586 | |
---|
| 587 | /* |
---|
| 588 | * _Thread_Tickle_timeslice |
---|
| 589 | * |
---|
| 590 | * DESCRIPTION: |
---|
| 591 | * |
---|
| 592 | * This routine is invoked as part of processing each clock tick. |
---|
| 593 | * It is responsible for determining if the current thread allows |
---|
| 594 | * timeslicing and, if so, when its timeslice expires. |
---|
| 595 | */ |
---|
| 596 | |
---|
| 597 | void _Thread_Tickle_timeslice( void ); |
---|
| 598 | |
---|
| 599 | /* |
---|
| 600 | * _Thread_Yield_processor |
---|
| 601 | * |
---|
| 602 | * DESCRIPTION: |
---|
| 603 | * |
---|
| 604 | * This routine is invoked when a thread wishes to voluntarily |
---|
| 605 | * transfer control of the processor to another thread of equal |
---|
| 606 | * or greater priority. |
---|
| 607 | */ |
---|
| 608 | |
---|
| 609 | void _Thread_Yield_processor( void ); |
---|
| 610 | |
---|
[eb02f47] | 611 | /* |
---|
| 612 | * _Thread_Rotate_Ready_Queue |
---|
| 613 | * |
---|
| 614 | * DESCRIPTION: |
---|
| 615 | * |
---|
| 616 | * This routine is invoked to rotate the ready queue for the |
---|
| 617 | * given priority. It can be used to yeild the processor |
---|
| 618 | * by rotating the executing threads ready queue. |
---|
| 619 | */ |
---|
| 620 | |
---|
| 621 | void _Thread_Rotate_Ready_Queue( |
---|
| 622 | Priority_Control priority |
---|
| 623 | ); |
---|
| 624 | |
---|
[ac7d5ef0] | 625 | /* |
---|
| 626 | * _Thread_Load_environment |
---|
| 627 | * |
---|
| 628 | * DESCRIPTION: |
---|
| 629 | * |
---|
| 630 | * This routine initializes the context of the_thread to its |
---|
| 631 | * appropriate starting state. |
---|
| 632 | */ |
---|
| 633 | |
---|
| 634 | void _Thread_Load_environment( |
---|
| 635 | Thread_Control *the_thread |
---|
| 636 | ); |
---|
| 637 | |
---|
| 638 | /* |
---|
| 639 | * _Thread_Handler |
---|
| 640 | * |
---|
| 641 | * DESCRIPTION: |
---|
| 642 | * |
---|
| 643 | * This routine is the wrapper function for all threads. It is |
---|
| 644 | * the starting point for all threads. The user provided thread |
---|
| 645 | * entry point is invoked by this routine. Operations |
---|
| 646 | * which must be performed immediately before and after the user's |
---|
| 647 | * thread executes are found here. |
---|
| 648 | */ |
---|
| 649 | |
---|
| 650 | void _Thread_Handler( void ); |
---|
| 651 | |
---|
| 652 | /* |
---|
| 653 | * _Thread_Delay_ended |
---|
| 654 | * |
---|
| 655 | * DESCRIPTION: |
---|
| 656 | * |
---|
| 657 | * This routine is invoked when a thread must be unblocked at the |
---|
[3a4ae6c] | 658 | * end of a time based delay (i.e. wake after or wake when). |
---|
[ac7d5ef0] | 659 | */ |
---|
| 660 | |
---|
| 661 | void _Thread_Delay_ended( |
---|
| 662 | Objects_Id id, |
---|
| 663 | void *ignored |
---|
| 664 | ); |
---|
| 665 | |
---|
| 666 | /* |
---|
| 667 | * _Thread_Change_priority |
---|
| 668 | * |
---|
| 669 | * DESCRIPTION: |
---|
| 670 | * |
---|
| 671 | * This routine changes the current priority of the_thread to |
---|
| 672 | * new_priority. It performs any necessary scheduling operations |
---|
| 673 | * including the selection of a new heir thread. |
---|
| 674 | */ |
---|
| 675 | |
---|
| 676 | void _Thread_Change_priority ( |
---|
| 677 | Thread_Control *the_thread, |
---|
[f926b34] | 678 | Priority_Control new_priority, |
---|
| 679 | boolean prepend_it |
---|
[ac7d5ef0] | 680 | ); |
---|
| 681 | |
---|
| 682 | /* |
---|
| 683 | * _Thread_Set_priority |
---|
| 684 | * |
---|
| 685 | * DESCRIPTION: |
---|
| 686 | * |
---|
| 687 | * This routine updates the priority related fields in the_thread |
---|
| 688 | * control block to indicate the current priority is now new_priority. |
---|
| 689 | */ |
---|
| 690 | |
---|
| 691 | void _Thread_Set_priority( |
---|
| 692 | Thread_Control *the_thread, |
---|
[7f6a24ab] | 693 | Priority_Control new_priority |
---|
[ac7d5ef0] | 694 | ); |
---|
| 695 | |
---|
[eb02f47] | 696 | /* |
---|
| 697 | * _Thread_Suspend |
---|
| 698 | * |
---|
| 699 | * DESCRIPTION: |
---|
| 700 | * |
---|
| 701 | * This routine updates the related suspend fields in the_thread |
---|
| 702 | * control block to indicate the current nested level. |
---|
| 703 | */ |
---|
| 704 | |
---|
| 705 | void _Thread_Suspend( |
---|
| 706 | Thread_Control *the_thread |
---|
| 707 | ); |
---|
| 708 | |
---|
| 709 | /* |
---|
| 710 | * _Thread_Resume |
---|
| 711 | * |
---|
| 712 | * DESCRIPTION: |
---|
| 713 | * |
---|
| 714 | * This routine updates the related suspend fields in the_thread |
---|
| 715 | * control block to indicate the current nested level. A force |
---|
| 716 | * parameter of TRUE will force a resume and clear the suspend count. |
---|
| 717 | */ |
---|
| 718 | |
---|
| 719 | void _Thread_Resume( |
---|
| 720 | Thread_Control *the_thread, |
---|
| 721 | boolean force |
---|
| 722 | ); |
---|
| 723 | |
---|
[ac7d5ef0] | 724 | /* |
---|
[3a4ae6c] | 725 | * _Thread_Evaluate_mode |
---|
[ac7d5ef0] | 726 | * |
---|
| 727 | * DESCRIPTION: |
---|
| 728 | * |
---|
[eb02f47] | 729 | * This routine evaluates the current scheduling information for the |
---|
| 730 | * system and determines if a context switch is required. This |
---|
| 731 | * is usually called after changing an execution mode such as preemptability |
---|
| 732 | * for a thread. |
---|
[ac7d5ef0] | 733 | */ |
---|
| 734 | |
---|
[3a4ae6c] | 735 | boolean _Thread_Evaluate_mode( void ); |
---|
[ac7d5ef0] | 736 | |
---|
[f4d52cd7] | 737 | /* |
---|
| 738 | * _Thread_Get |
---|
| 739 | * |
---|
| 740 | * NOTE: If we are not using static inlines, this must be a real |
---|
| 741 | * subroutine call. |
---|
| 742 | */ |
---|
| 743 | |
---|
[8af72be] | 744 | #ifndef RTEMS_INLINES |
---|
[f4d52cd7] | 745 | Thread_Control *_Thread_Get ( |
---|
| 746 | Objects_Id id, |
---|
| 747 | Objects_Locations *location |
---|
| 748 | ); |
---|
| 749 | #endif |
---|
| 750 | |
---|
[adf98bd] | 751 | /* |
---|
| 752 | * _Thread_Idle_body |
---|
| 753 | * |
---|
| 754 | * DESCRIPTION: |
---|
| 755 | * |
---|
| 756 | * This routine is the body of the system idle thread. |
---|
| 757 | */ |
---|
| 758 | |
---|
| 759 | #if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE) |
---|
| 760 | Thread _Thread_Idle_body( |
---|
[d6154c7] | 761 | uint32_t ignored |
---|
[adf98bd] | 762 | ); |
---|
| 763 | #endif |
---|
| 764 | |
---|
[17c66867] | 765 | /* |
---|
| 766 | * rtems_iterate_over_all_tasks |
---|
| 767 | * |
---|
| 768 | * DESCRIPTION: |
---|
| 769 | * |
---|
| 770 | * This routine iterates over all threads regardless of API and |
---|
| 771 | * invokes the specified routine. |
---|
| 772 | */ |
---|
| 773 | |
---|
| 774 | typedef void (*rtems_per_thread_routine)( Thread_Control * ); |
---|
| 775 | |
---|
| 776 | void rtems_iterate_over_all_threads( |
---|
| 777 | rtems_per_thread_routine routine |
---|
| 778 | ); |
---|
| 779 | |
---|
[1a8fde6c] | 780 | #ifndef __RTEMS_APPLICATION__ |
---|
[5e9b32b] | 781 | #include <rtems/score/thread.inl> |
---|
[1a8fde6c] | 782 | #endif |
---|
[97e2729d] | 783 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[5e9b32b] | 784 | #include <rtems/score/threadmp.h> |
---|
[97e2729d] | 785 | #endif |
---|
[ac7d5ef0] | 786 | |
---|
| 787 | #ifdef __cplusplus |
---|
| 788 | } |
---|
| 789 | #endif |
---|
| 790 | |
---|
| 791 | #endif |
---|
| 792 | /* end of include file */ |
---|