1 | /** |
---|
2 | * @file rtems/score/thread.h |
---|
3 | * |
---|
4 | * This include file contains all constants and structures associated |
---|
5 | * with the thread control block. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2009. |
---|
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_THREAD_H |
---|
20 | #define _RTEMS_SCORE_THREAD_H |
---|
21 | |
---|
22 | /** |
---|
23 | * @defgroup ScoreThread Thread Handler |
---|
24 | * |
---|
25 | * This handler encapsulates functionality related to the management of |
---|
26 | * threads. This includes the creation, deletion, and scheduling of threads. |
---|
27 | * |
---|
28 | * The following variables are maintained as part of the per cpu data |
---|
29 | * structure. |
---|
30 | * |
---|
31 | * + Idle thread pointer |
---|
32 | * + Executing thread pointer |
---|
33 | * + Heir thread pointer |
---|
34 | */ |
---|
35 | /**@{*/ |
---|
36 | |
---|
37 | #if defined(RTEMS_POSIX_API) |
---|
38 | #define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE |
---|
39 | #endif |
---|
40 | |
---|
41 | #if defined(RTEMS_POSIX_API) |
---|
42 | #define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT |
---|
43 | #endif |
---|
44 | |
---|
45 | #if defined(RTEMS_POSIX_API) |
---|
46 | #define RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API |
---|
47 | #endif |
---|
48 | |
---|
49 | #ifdef __cplusplus |
---|
50 | extern "C" { |
---|
51 | #endif |
---|
52 | |
---|
53 | /* |
---|
54 | * The user can define this at configure time and go back to ticks |
---|
55 | * resolution. |
---|
56 | */ |
---|
57 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
58 | #include <rtems/score/timestamp.h> |
---|
59 | |
---|
60 | typedef Timestamp_Control Thread_CPU_usage_t; |
---|
61 | #else |
---|
62 | typedef uint32_t Thread_CPU_usage_t; |
---|
63 | #endif |
---|
64 | |
---|
65 | #include <rtems/score/percpu.h> |
---|
66 | #include <rtems/score/context.h> |
---|
67 | #include <rtems/score/cpu.h> |
---|
68 | #if defined(RTEMS_MULTIPROCESSING) |
---|
69 | #include <rtems/score/mppkt.h> |
---|
70 | #endif |
---|
71 | #include <rtems/score/object.h> |
---|
72 | #include <rtems/score/priority.h> |
---|
73 | #include <rtems/score/stack.h> |
---|
74 | #include <rtems/score/states.h> |
---|
75 | #include <rtems/score/tod.h> |
---|
76 | #include <rtems/score/tqdata.h> |
---|
77 | #include <rtems/score/watchdog.h> |
---|
78 | |
---|
79 | /** |
---|
80 | * The following defines the "return type" of a thread. |
---|
81 | * |
---|
82 | * @note This cannot always be right. Some APIs have void |
---|
83 | * tasks/threads, others return pointers, others may |
---|
84 | * return a numeric value. Hopefully a pointer is |
---|
85 | * always at least as big as an uint32_t . :) |
---|
86 | */ |
---|
87 | typedef void *Thread; |
---|
88 | |
---|
89 | /** |
---|
90 | * @brief Type of the numeric argument of a thread entry function with at |
---|
91 | * least one numeric argument. |
---|
92 | * |
---|
93 | * This numeric argument type designates an unsigned integer type with the |
---|
94 | * property that any valid pointer to void can be converted to this type and |
---|
95 | * then converted back to a pointer to void. The result will compare equal to |
---|
96 | * the original pointer. |
---|
97 | */ |
---|
98 | typedef uintptr_t Thread_Entry_numeric_type; |
---|
99 | |
---|
100 | /** |
---|
101 | * The following defines the ways in which the entry point for a |
---|
102 | * thread can be invoked. Basically, it can be passed any |
---|
103 | * combination/permutation of a pointer and an uint32_t value. |
---|
104 | * |
---|
105 | * @note For now, we are ignoring the return type. |
---|
106 | */ |
---|
107 | typedef enum { |
---|
108 | THREAD_START_NUMERIC, |
---|
109 | THREAD_START_POINTER, |
---|
110 | #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API) |
---|
111 | THREAD_START_BOTH_POINTER_FIRST, |
---|
112 | THREAD_START_BOTH_NUMERIC_FIRST |
---|
113 | #endif |
---|
114 | } Thread_Start_types; |
---|
115 | |
---|
116 | /** This type corresponds to a very simple style thread entry point. */ |
---|
117 | typedef Thread ( *Thread_Entry )( void ); /* basic type */ |
---|
118 | |
---|
119 | /** This type corresponds to a thread entry point which takes a single |
---|
120 | * unsigned thirty-two bit integer as an argument. |
---|
121 | */ |
---|
122 | typedef Thread ( *Thread_Entry_numeric )( Thread_Entry_numeric_type ); |
---|
123 | |
---|
124 | /** This type corresponds to a thread entry point which takes a single |
---|
125 | * untyped pointer as an argument. |
---|
126 | */ |
---|
127 | typedef Thread ( *Thread_Entry_pointer )( void * ); |
---|
128 | |
---|
129 | /** This type corresponds to a thread entry point which takes a single |
---|
130 | * untyped pointer and an unsigned thirty-two bit integer as arguments. |
---|
131 | */ |
---|
132 | typedef Thread ( *Thread_Entry_both_pointer_first )( void *, Thread_Entry_numeric_type ); |
---|
133 | |
---|
134 | /** This type corresponds to a thread entry point which takes a single |
---|
135 | * unsigned thirty-two bit integer and an untyped pointer and an |
---|
136 | * as arguments. |
---|
137 | */ |
---|
138 | typedef Thread ( *Thread_Entry_both_numeric_first )( Thread_Entry_numeric_type, void * ); |
---|
139 | |
---|
140 | /** |
---|
141 | * The following lists the algorithms used to manage the thread cpu budget. |
---|
142 | * |
---|
143 | * Reset Timeslice: At each context switch, reset the time quantum. |
---|
144 | * Exhaust Timeslice: Only reset the quantum once it is consumed. |
---|
145 | * Callout: Execute routine when budget is consumed. |
---|
146 | */ |
---|
147 | typedef enum { |
---|
148 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
149 | THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE, |
---|
150 | #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) |
---|
151 | THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE, |
---|
152 | #endif |
---|
153 | #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT) |
---|
154 | THREAD_CPU_BUDGET_ALGORITHM_CALLOUT |
---|
155 | #endif |
---|
156 | } Thread_CPU_budget_algorithms; |
---|
157 | |
---|
158 | /** This defines thes the entry point for the thread specific timeslice |
---|
159 | * budget management algorithm. |
---|
160 | */ |
---|
161 | typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * ); |
---|
162 | |
---|
163 | /** @brief Per Task Variable Manager Structure Forward Reference |
---|
164 | * |
---|
165 | * Forward reference to the per task variable structure. |
---|
166 | */ |
---|
167 | struct rtems_task_variable_tt; |
---|
168 | |
---|
169 | /** @brief Per Task Variable Manager Structure |
---|
170 | * |
---|
171 | * This is the internal structure used to manager per Task Variables. |
---|
172 | */ |
---|
173 | typedef struct { |
---|
174 | /** This field points to the next per task variable for this task. */ |
---|
175 | struct rtems_task_variable_tt *next; |
---|
176 | /** This field points to the physical memory location of this per |
---|
177 | * task variable. |
---|
178 | */ |
---|
179 | void **ptr; |
---|
180 | /** This field is to the global value for this per task variable. */ |
---|
181 | void *gval; |
---|
182 | /** This field is to this thread's value for this per task variable. */ |
---|
183 | void *tval; |
---|
184 | /** This field points to the destructor for this per task variable. */ |
---|
185 | void (*dtor)(void *); |
---|
186 | } rtems_task_variable_t; |
---|
187 | |
---|
188 | /** |
---|
189 | * The following structure contains the information which defines |
---|
190 | * the starting state of a thread. |
---|
191 | */ |
---|
192 | typedef struct { |
---|
193 | /** This field is the starting address for the thread. */ |
---|
194 | Thread_Entry entry_point; |
---|
195 | /** This field indicates the how task is invoked. */ |
---|
196 | Thread_Start_types prototype; |
---|
197 | /** This field is the pointer argument passed at thread start. */ |
---|
198 | void *pointer_argument; |
---|
199 | /** This field is the numeric argument passed at thread start. */ |
---|
200 | Thread_Entry_numeric_type numeric_argument; |
---|
201 | /*-------------- initial execution modes ----------------- */ |
---|
202 | /** This field indicates whether the thread was preemptible when |
---|
203 | * it started. |
---|
204 | */ |
---|
205 | bool is_preemptible; |
---|
206 | /** This field indicates the CPU budget algorith. */ |
---|
207 | Thread_CPU_budget_algorithms budget_algorithm; |
---|
208 | /** This field is the routine to invoke when the CPU allotment is |
---|
209 | * consumed. |
---|
210 | */ |
---|
211 | Thread_CPU_budget_algorithm_callout budget_callout; |
---|
212 | /** This field is the initial ISR disable level of this thread. */ |
---|
213 | uint32_t isr_level; |
---|
214 | /** This field is the initial priority. */ |
---|
215 | Priority_Control initial_priority; |
---|
216 | #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API) |
---|
217 | /** This field indicates whether the SuperCore allocated the stack. */ |
---|
218 | bool core_allocated_stack; |
---|
219 | #endif |
---|
220 | /** This field is the stack information. */ |
---|
221 | Stack_Control Initial_stack; |
---|
222 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
223 | /** This field is the initial FP context area address. */ |
---|
224 | Context_Control_fp *fp_context; |
---|
225 | #endif |
---|
226 | /** This field is the initial stack area address. */ |
---|
227 | void *stack; |
---|
228 | } Thread_Start_information; |
---|
229 | |
---|
230 | /** |
---|
231 | * The following structure contains the information necessary to manage |
---|
232 | * a thread which it is waiting for a resource. |
---|
233 | */ |
---|
234 | #define THREAD_STATUS_PROXY_BLOCKING 0x1111111 |
---|
235 | |
---|
236 | /** |
---|
237 | * @brief Union type to hold a pointer to an immutable or a mutable object. |
---|
238 | * |
---|
239 | * The main purpose is to enable passing of pointers to read-only send buffers |
---|
240 | * in the message passing subsystem. This approach is somewhat fragile since |
---|
241 | * it prevents the compiler to check if the operations on objects are valid |
---|
242 | * with respect to the constant qualifier. An alternative would be to add a |
---|
243 | * third pointer argument for immutable objects, but this would increase the |
---|
244 | * structure size. |
---|
245 | */ |
---|
246 | typedef union { |
---|
247 | void *mutable_object; |
---|
248 | const void *immutable_object; |
---|
249 | } Thread_Wait_information_Object_argument_type; |
---|
250 | |
---|
251 | /** @brief Thread Blocking Management Information |
---|
252 | * |
---|
253 | * This contains the information required to manage a thread while it is |
---|
254 | * blocked and to return information to it. |
---|
255 | */ |
---|
256 | typedef struct { |
---|
257 | /** This field is the Id of the object this thread is waiting upon. */ |
---|
258 | Objects_Id id; |
---|
259 | /** This field is used to return an integer while when blocked. */ |
---|
260 | uint32_t count; |
---|
261 | /** This field is for a pointer to a user return argument. */ |
---|
262 | void *return_argument; |
---|
263 | /** This field is for a pointer to a second user return argument. */ |
---|
264 | Thread_Wait_information_Object_argument_type |
---|
265 | return_argument_second; |
---|
266 | /** This field contains any options in effect on this blocking operation. */ |
---|
267 | uint32_t option; |
---|
268 | /** This field will contain the return status from a blocking operation. |
---|
269 | * |
---|
270 | * @note The following assumes that all API return codes can be |
---|
271 | * treated as an uint32_t. |
---|
272 | */ |
---|
273 | uint32_t return_code; |
---|
274 | |
---|
275 | /** This field is the chain header for the second through Nth tasks |
---|
276 | * of the same priority blocked waiting on the same object. |
---|
277 | */ |
---|
278 | Chain_Control Block2n; |
---|
279 | /** This field points to the thread queue on which this thread is blocked. */ |
---|
280 | Thread_queue_Control *queue; |
---|
281 | } Thread_Wait_information; |
---|
282 | |
---|
283 | /** |
---|
284 | * The following defines the control block used to manage |
---|
285 | * each thread proxy. |
---|
286 | * |
---|
287 | * @note It is critical that proxies and threads have identical |
---|
288 | * memory images for the shared part. |
---|
289 | */ |
---|
290 | typedef struct { |
---|
291 | /** This field is the object management structure for each proxy. */ |
---|
292 | Objects_Control Object; |
---|
293 | /** This field is the current execution state of this proxy. */ |
---|
294 | States_Control current_state; |
---|
295 | /** This field is the current priority state of this proxy. */ |
---|
296 | Priority_Control current_priority; |
---|
297 | /** This field is the base priority of this proxy. */ |
---|
298 | Priority_Control real_priority; |
---|
299 | /** This field is the number of mutexes currently held by this proxy. */ |
---|
300 | uint32_t resource_count; |
---|
301 | |
---|
302 | /** This field is the blocking information for this proxy. */ |
---|
303 | Thread_Wait_information Wait; |
---|
304 | /** This field is the Watchdog used to manage proxy delays and timeouts. */ |
---|
305 | Watchdog_Control Timer; |
---|
306 | #if defined(RTEMS_MULTIPROCESSING) |
---|
307 | /** This field is the received response packet in an MP system. */ |
---|
308 | MP_packet_Prefix *receive_packet; |
---|
309 | #endif |
---|
310 | /****************** end of common block ********************/ |
---|
311 | /** This field is used to manage the set of proxies in the system. */ |
---|
312 | Chain_Node Active; |
---|
313 | } Thread_Proxy_control; |
---|
314 | |
---|
315 | /** |
---|
316 | * The following record defines the control block used |
---|
317 | * to manage each thread. |
---|
318 | * |
---|
319 | * @note It is critical that proxies and threads have identical |
---|
320 | * memory images for the shared part. |
---|
321 | */ |
---|
322 | typedef enum { |
---|
323 | /** This value is for the Classic RTEMS API. */ |
---|
324 | THREAD_API_RTEMS, |
---|
325 | /** This value is for the POSIX API. */ |
---|
326 | THREAD_API_POSIX |
---|
327 | } Thread_APIs; |
---|
328 | |
---|
329 | /** This macro defines the first API which has threads. */ |
---|
330 | #define THREAD_API_FIRST THREAD_API_RTEMS |
---|
331 | |
---|
332 | /** This macro defines the last API which has threads. */ |
---|
333 | #define THREAD_API_LAST THREAD_API_POSIX |
---|
334 | |
---|
335 | /** |
---|
336 | * This structure defines the Thread Control Block (TCB). |
---|
337 | */ |
---|
338 | struct Thread_Control_struct { |
---|
339 | /** This field is the object management structure for each thread. */ |
---|
340 | Objects_Control Object; |
---|
341 | /** This field is the current execution state of this thread. */ |
---|
342 | States_Control current_state; |
---|
343 | /** This field is the current priority state of this thread. */ |
---|
344 | Priority_Control current_priority; |
---|
345 | /** This field is the base priority of this thread. */ |
---|
346 | Priority_Control real_priority; |
---|
347 | /** This field is the number of mutexes currently held by this thread. */ |
---|
348 | uint32_t resource_count; |
---|
349 | /** This field is the blocking information for this thread. */ |
---|
350 | Thread_Wait_information Wait; |
---|
351 | /** This field is the Watchdog used to manage thread delays and timeouts. */ |
---|
352 | Watchdog_Control Timer; |
---|
353 | #if defined(RTEMS_MULTIPROCESSING) |
---|
354 | /** This field is the received response packet in an MP system. */ |
---|
355 | MP_packet_Prefix *receive_packet; |
---|
356 | #endif |
---|
357 | #ifdef __RTEMS_STRICT_ORDER_MUTEX__ |
---|
358 | /** This field is the head of queue of priority inheritance mutex |
---|
359 | * held by the thread. |
---|
360 | */ |
---|
361 | Chain_Control lock_mutex; |
---|
362 | #endif |
---|
363 | /*================= end of common block =================*/ |
---|
364 | /** This field is the number of nested suspend calls. */ |
---|
365 | uint32_t suspend_count; |
---|
366 | #if defined(RTEMS_MULTIPROCESSING) |
---|
367 | /** This field is true if the thread is offered globally */ |
---|
368 | bool is_global; |
---|
369 | #endif |
---|
370 | /** This field is true if the thread is preemptible. */ |
---|
371 | bool is_preemptible; |
---|
372 | #if __RTEMS_ADA__ |
---|
373 | /** This field is the GNAT self context pointer. */ |
---|
374 | void *rtems_ada_self; |
---|
375 | #endif |
---|
376 | /** This field is the length of the time quantum that this thread is |
---|
377 | * allowed to consume. The algorithm used to manage limits on CPU usage |
---|
378 | * is specified by budget_algorithm. |
---|
379 | */ |
---|
380 | uint32_t cpu_time_budget; |
---|
381 | /** This field is the algorithm used to manage this thread's time |
---|
382 | * quantum. The algorithm may be specified as none which case, |
---|
383 | * no limit is in place. |
---|
384 | */ |
---|
385 | Thread_CPU_budget_algorithms budget_algorithm; |
---|
386 | /** This field is the method invoked with the budgeted time is consumed. */ |
---|
387 | Thread_CPU_budget_algorithm_callout budget_callout; |
---|
388 | /** This field is the amount of CPU time consumed by this thread |
---|
389 | * since it was created. |
---|
390 | */ |
---|
391 | Thread_CPU_usage_t cpu_time_used; |
---|
392 | /** This field points to the Ready FIFO for this priority. */ |
---|
393 | Chain_Control *ready; |
---|
394 | /** This field contains precalculated priority map indices. */ |
---|
395 | Priority_Information Priority_map; |
---|
396 | /** This field contains information about the starting state of |
---|
397 | * this thread. |
---|
398 | */ |
---|
399 | Thread_Start_information Start; |
---|
400 | /** This field contains the context of this thread. */ |
---|
401 | Context_Control Registers; |
---|
402 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
403 | /** This field points to the floating point context for this thread. |
---|
404 | * If NULL, the thread is integer only. |
---|
405 | */ |
---|
406 | Context_Control_fp *fp_context; |
---|
407 | #endif |
---|
408 | /** This field points to the newlib reentrancy structure for this thread. */ |
---|
409 | struct _reent *libc_reent; |
---|
410 | /** This array contains the API extension area pointers. */ |
---|
411 | void *API_Extensions[ THREAD_API_LAST + 1 ]; |
---|
412 | /** This field points to the user extension pointers. */ |
---|
413 | void **extensions; |
---|
414 | /** This field points to the set of per task variables. */ |
---|
415 | rtems_task_variable_t *task_variables; |
---|
416 | }; |
---|
417 | |
---|
418 | /** |
---|
419 | * Self for the GNU Ada Run-Time |
---|
420 | */ |
---|
421 | SCORE_EXTERN void *rtems_ada_self; |
---|
422 | |
---|
423 | /** |
---|
424 | * The following defines the information control block used to |
---|
425 | * manage this class of objects. |
---|
426 | */ |
---|
427 | SCORE_EXTERN Objects_Information _Thread_Internal_information; |
---|
428 | |
---|
429 | /** |
---|
430 | * The following context area contains the context of the "thread" |
---|
431 | * which invoked the start multitasking routine. This context is |
---|
432 | * restored as the last action of the stop multitasking routine. Thus |
---|
433 | * control of the processor can be returned to the environment |
---|
434 | * which initiated the system. |
---|
435 | */ |
---|
436 | SCORE_EXTERN Context_Control _Thread_BSP_context; |
---|
437 | |
---|
438 | /** |
---|
439 | * The following declares the dispatch critical section nesting |
---|
440 | * counter which is used to prevent context switches at inopportune |
---|
441 | * moments. |
---|
442 | */ |
---|
443 | SCORE_EXTERN volatile uint32_t _Thread_Dispatch_disable_level; |
---|
444 | |
---|
445 | /** |
---|
446 | * The following holds how many user extensions are in the system. This |
---|
447 | * is used to determine how many user extension data areas to allocate |
---|
448 | * per thread. |
---|
449 | */ |
---|
450 | SCORE_EXTERN uint32_t _Thread_Maximum_extensions; |
---|
451 | |
---|
452 | /** |
---|
453 | * The following is used to manage the length of a timeslice quantum. |
---|
454 | */ |
---|
455 | SCORE_EXTERN uint32_t _Thread_Ticks_per_timeslice; |
---|
456 | |
---|
457 | /** |
---|
458 | * The following points to the array of FIFOs used to manage the |
---|
459 | * set of ready threads. |
---|
460 | */ |
---|
461 | SCORE_EXTERN Chain_Control *_Thread_Ready_chain; |
---|
462 | |
---|
463 | /** |
---|
464 | * The following points to the thread whose floating point |
---|
465 | * context is currently loaded. |
---|
466 | */ |
---|
467 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
468 | SCORE_EXTERN Thread_Control *_Thread_Allocated_fp; |
---|
469 | #endif |
---|
470 | |
---|
471 | /** |
---|
472 | * The C library re-enter-rant global pointer. Some C library implementations |
---|
473 | * such as newlib have a single global pointer that changed during a context |
---|
474 | * switch. The pointer points to that global pointer. The Thread control block |
---|
475 | * holds a pointer to the task specific data. |
---|
476 | */ |
---|
477 | SCORE_EXTERN struct _reent **_Thread_libc_reent; |
---|
478 | |
---|
479 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
480 | |
---|
481 | /** |
---|
482 | * This contains the time since boot when the last context switch occurred. |
---|
483 | * By placing it in the BSS, it will automatically be zeroed out at |
---|
484 | * system initialization and does not need to be known outside this |
---|
485 | * file. |
---|
486 | */ |
---|
487 | SCORE_EXTERN Timestamp_Control _Thread_Time_of_last_context_switch; |
---|
488 | #endif |
---|
489 | |
---|
490 | /** |
---|
491 | * This routine performs the initialization necessary for this handler. |
---|
492 | */ |
---|
493 | void _Thread_Handler_initialization(void); |
---|
494 | |
---|
495 | /** |
---|
496 | * This routine creates the idle thread. |
---|
497 | * |
---|
498 | * @warning No thread should be created before this one. |
---|
499 | */ |
---|
500 | void _Thread_Create_idle(void); |
---|
501 | |
---|
502 | /** |
---|
503 | * This routine initiates multitasking. It is invoked only as |
---|
504 | * part of initialization and its invocation is the last act of |
---|
505 | * the non-multitasking part of the system initialization. |
---|
506 | */ |
---|
507 | void _Thread_Start_multitasking( void ); |
---|
508 | |
---|
509 | /** |
---|
510 | * This routine is responsible for transferring control of the |
---|
511 | * processor from the executing thread to the heir thread. As part |
---|
512 | * of this process, it is responsible for the following actions: |
---|
513 | * |
---|
514 | * + saving the context of the executing thread |
---|
515 | * + restoring the context of the heir thread |
---|
516 | * + dispatching any signals for the resulting executing thread |
---|
517 | */ |
---|
518 | void _Thread_Dispatch( void ); |
---|
519 | |
---|
520 | /** |
---|
521 | * Allocate the requested stack space for the thread. |
---|
522 | * return the actual size allocated after any adjustment |
---|
523 | * or return zero if the allocation failed. |
---|
524 | * Set the Start.stack field to the address of the stack |
---|
525 | */ |
---|
526 | |
---|
527 | size_t _Thread_Stack_Allocate( |
---|
528 | Thread_Control *the_thread, |
---|
529 | size_t stack_size |
---|
530 | ); |
---|
531 | |
---|
532 | /** |
---|
533 | * Deallocate the Thread's stack. |
---|
534 | */ |
---|
535 | void _Thread_Stack_Free( |
---|
536 | Thread_Control *the_thread |
---|
537 | ); |
---|
538 | |
---|
539 | /** |
---|
540 | * This routine initializes the specified the thread. It allocates |
---|
541 | * all memory associated with this thread. It completes by adding |
---|
542 | * the thread to the local object table so operations on this |
---|
543 | * thread id are allowed. |
---|
544 | * |
---|
545 | * @note If stack_area is NULL, it is allocated from the workspace. |
---|
546 | * |
---|
547 | * @note If the stack is allocated from the workspace, then it is |
---|
548 | * guaranteed to be of at least minimum size. |
---|
549 | */ |
---|
550 | bool _Thread_Initialize( |
---|
551 | Objects_Information *information, |
---|
552 | Thread_Control *the_thread, |
---|
553 | void *stack_area, |
---|
554 | size_t stack_size, |
---|
555 | bool is_fp, |
---|
556 | Priority_Control priority, |
---|
557 | bool is_preemptible, |
---|
558 | Thread_CPU_budget_algorithms budget_algorithm, |
---|
559 | Thread_CPU_budget_algorithm_callout budget_callout, |
---|
560 | uint32_t isr_level, |
---|
561 | Objects_Name name |
---|
562 | ); |
---|
563 | |
---|
564 | /** |
---|
565 | * This routine initializes the executable information for a thread |
---|
566 | * and makes it ready to execute. After this routine executes, the |
---|
567 | * thread competes with all other threads for CPU time. |
---|
568 | */ |
---|
569 | bool _Thread_Start( |
---|
570 | Thread_Control *the_thread, |
---|
571 | Thread_Start_types the_prototype, |
---|
572 | void *entry_point, |
---|
573 | void *pointer_argument, |
---|
574 | Thread_Entry_numeric_type numeric_argument |
---|
575 | ); |
---|
576 | |
---|
577 | /** |
---|
578 | * This support routine restarts the specified task in a way that the |
---|
579 | * next time this thread executes, it will begin execution at its |
---|
580 | * original starting point. |
---|
581 | * |
---|
582 | * TODO: multiple task arg profiles |
---|
583 | */ |
---|
584 | bool _Thread_Restart( |
---|
585 | Thread_Control *the_thread, |
---|
586 | void *pointer_argument, |
---|
587 | Thread_Entry_numeric_type numeric_argument |
---|
588 | ); |
---|
589 | |
---|
590 | /** |
---|
591 | * This routine resets a thread to its initial state but does |
---|
592 | * not restart it. |
---|
593 | */ |
---|
594 | void _Thread_Reset( |
---|
595 | Thread_Control *the_thread, |
---|
596 | void *pointer_argument, |
---|
597 | Thread_Entry_numeric_type numeric_argument |
---|
598 | ); |
---|
599 | |
---|
600 | /** |
---|
601 | * This routine frees all memory associated with the specified |
---|
602 | * thread and removes it from the local object table so no further |
---|
603 | * operations on this thread are allowed. |
---|
604 | */ |
---|
605 | void _Thread_Close( |
---|
606 | Objects_Information *information, |
---|
607 | Thread_Control *the_thread |
---|
608 | ); |
---|
609 | |
---|
610 | /** |
---|
611 | * This routine removes any set states for the_thread. It performs |
---|
612 | * any necessary scheduling operations including the selection of |
---|
613 | * a new heir thread. |
---|
614 | */ |
---|
615 | void _Thread_Ready( |
---|
616 | Thread_Control *the_thread |
---|
617 | ); |
---|
618 | |
---|
619 | /** |
---|
620 | * This routine clears the indicated STATES for the_thread. It performs |
---|
621 | * any necessary scheduling operations including the selection of |
---|
622 | * a new heir thread. |
---|
623 | */ |
---|
624 | void _Thread_Clear_state( |
---|
625 | Thread_Control *the_thread, |
---|
626 | States_Control state |
---|
627 | ); |
---|
628 | |
---|
629 | /** |
---|
630 | * This routine sets the indicated states for the_thread. It performs |
---|
631 | * any necessary scheduling operations including the selection of |
---|
632 | * a new heir thread. |
---|
633 | */ |
---|
634 | void _Thread_Set_state( |
---|
635 | Thread_Control *the_thread, |
---|
636 | States_Control state |
---|
637 | ); |
---|
638 | |
---|
639 | /** |
---|
640 | * This routine sets the TRANSIENT state for the_thread. It performs |
---|
641 | * any necessary scheduling operations including the selection of |
---|
642 | * a new heir thread. |
---|
643 | */ |
---|
644 | void _Thread_Set_transient( |
---|
645 | Thread_Control *the_thread |
---|
646 | ); |
---|
647 | |
---|
648 | /** |
---|
649 | * This routine is invoked as part of processing each clock tick. |
---|
650 | * It is responsible for determining if the current thread allows |
---|
651 | * timeslicing and, if so, when its timeslice expires. |
---|
652 | */ |
---|
653 | void _Thread_Tickle_timeslice( void ); |
---|
654 | |
---|
655 | /** |
---|
656 | * This routine is invoked when a thread wishes to voluntarily |
---|
657 | * transfer control of the processor to another thread of equal |
---|
658 | * or greater priority. |
---|
659 | */ |
---|
660 | void _Thread_Yield_processor( void ); |
---|
661 | |
---|
662 | /** |
---|
663 | * This routine initializes the context of the_thread to its |
---|
664 | * appropriate starting state. |
---|
665 | */ |
---|
666 | void _Thread_Load_environment( |
---|
667 | Thread_Control *the_thread |
---|
668 | ); |
---|
669 | |
---|
670 | /** |
---|
671 | * This routine is the wrapper function for all threads. It is |
---|
672 | * the starting point for all threads. The user provided thread |
---|
673 | * entry point is invoked by this routine. Operations |
---|
674 | * which must be performed immediately before and after the user's |
---|
675 | * thread executes are found here. |
---|
676 | */ |
---|
677 | void _Thread_Handler( void ); |
---|
678 | |
---|
679 | /** |
---|
680 | * This routine is invoked when a thread must be unblocked at the |
---|
681 | * end of a time based delay (i.e. wake after or wake when). |
---|
682 | */ |
---|
683 | void _Thread_Delay_ended( |
---|
684 | Objects_Id id, |
---|
685 | void *ignored |
---|
686 | ); |
---|
687 | |
---|
688 | /** |
---|
689 | * This routine changes the current priority of the_thread to |
---|
690 | * new_priority. It performs any necessary scheduling operations |
---|
691 | * including the selection of a new heir thread. |
---|
692 | */ |
---|
693 | void _Thread_Change_priority ( |
---|
694 | Thread_Control *the_thread, |
---|
695 | Priority_Control new_priority, |
---|
696 | bool prepend_it |
---|
697 | ); |
---|
698 | |
---|
699 | /** |
---|
700 | * This routine updates the priority related fields in the_thread |
---|
701 | * control block to indicate the current priority is now new_priority. |
---|
702 | */ |
---|
703 | void _Thread_Set_priority( |
---|
704 | Thread_Control *the_thread, |
---|
705 | Priority_Control new_priority |
---|
706 | ); |
---|
707 | |
---|
708 | /** |
---|
709 | * This routine updates the related suspend fields in the_thread |
---|
710 | * control block to indicate the current nested level. |
---|
711 | */ |
---|
712 | void _Thread_Suspend( |
---|
713 | Thread_Control *the_thread |
---|
714 | ); |
---|
715 | |
---|
716 | /** |
---|
717 | * This routine updates the related suspend fields in the_thread |
---|
718 | * control block to indicate the current nested level. A force |
---|
719 | * parameter of true will force a resume and clear the suspend count. |
---|
720 | */ |
---|
721 | void _Thread_Resume( |
---|
722 | Thread_Control *the_thread, |
---|
723 | bool force |
---|
724 | ); |
---|
725 | |
---|
726 | #if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE) |
---|
727 | /** |
---|
728 | * This routine is the body of the system idle thread. |
---|
729 | * |
---|
730 | * NOTE: This routine is actually instantiated by confdefs.h when needed. |
---|
731 | */ |
---|
732 | void *_Thread_Idle_body( |
---|
733 | uintptr_t ignored |
---|
734 | ); |
---|
735 | #endif |
---|
736 | |
---|
737 | /** This defines the type for a method which operates on a single thread. |
---|
738 | */ |
---|
739 | typedef void (*rtems_per_thread_routine)( Thread_Control * ); |
---|
740 | |
---|
741 | /** |
---|
742 | * This routine iterates over all threads regardless of API and |
---|
743 | * invokes the specified routine. |
---|
744 | */ |
---|
745 | void rtems_iterate_over_all_threads( |
---|
746 | rtems_per_thread_routine routine |
---|
747 | ); |
---|
748 | |
---|
749 | /** |
---|
750 | * This function maps thread IDs to thread control |
---|
751 | * blocks. If ID corresponds to a local thread, then it |
---|
752 | * returns the_thread control pointer which maps to ID |
---|
753 | * and location is set to OBJECTS_LOCAL. If the thread ID is |
---|
754 | * global and resides on a remote node, then location is set |
---|
755 | * to OBJECTS_REMOTE, and the_thread is undefined. |
---|
756 | * Otherwise, location is set to OBJECTS_ERROR and |
---|
757 | * the_thread is undefined. |
---|
758 | * |
---|
759 | * @note The performance of many RTEMS services depends upon |
---|
760 | * the quick execution of the "good object" path in this |
---|
761 | * routine. If there is a possibility of saving a few |
---|
762 | * cycles off the execution time, this routine is worth |
---|
763 | * further optimization attention. |
---|
764 | */ |
---|
765 | Thread_Control *_Thread_Get ( |
---|
766 | Objects_Id id, |
---|
767 | Objects_Locations *location |
---|
768 | ); |
---|
769 | |
---|
770 | /** |
---|
771 | * @brief Cancel a blocking operation due to ISR |
---|
772 | * |
---|
773 | * This method is used to cancel a blocking operation that was |
---|
774 | * satisfied from an ISR while the thread executing was in the |
---|
775 | * process of blocking. |
---|
776 | * |
---|
777 | * @param[in] sync_state is the synchronization state |
---|
778 | * @param[in] the_thread is the thread whose blocking is canceled |
---|
779 | * @param[in] level is the previous ISR disable level |
---|
780 | * |
---|
781 | * @note This is a rare routine in RTEMS. It is called with |
---|
782 | * interrupts disabled and only when an ISR completed |
---|
783 | * a blocking condition in process. |
---|
784 | */ |
---|
785 | void _Thread_blocking_operation_Cancel( |
---|
786 | Thread_blocking_operation_States sync_state, |
---|
787 | Thread_Control *the_thread, |
---|
788 | ISR_Level level |
---|
789 | ); |
---|
790 | |
---|
791 | #ifndef __RTEMS_APPLICATION__ |
---|
792 | #include <rtems/score/thread.inl> |
---|
793 | #endif |
---|
794 | #if defined(RTEMS_MULTIPROCESSING) |
---|
795 | #include <rtems/score/threadmp.h> |
---|
796 | #endif |
---|
797 | |
---|
798 | #ifdef __cplusplus |
---|
799 | } |
---|
800 | #endif |
---|
801 | |
---|
802 | /**@}*/ |
---|
803 | |
---|
804 | #endif |
---|
805 | /* end of include file */ |
---|