source: rtems/c/src/exec/score/headers/thread.h @ f926b34

4.104.114.84.95
Last change on this file since f926b34 was f926b34, checked in by Joel Sherrill <joel.sherrill@…>, on 03/08/97 at 03:51:55

Modified calls to _Thread_Change_priority to take a third argument. The new
argument indicates whether the task is to be placed at the head or tail of
its priority fifo when it is lowering its own priority. POSIX normally
follows the RTEMS API conventions but GNAT expects that all lowering of
a task's priority by the task itself will result in being placed at the
head of the priority FIFO. Normally, this would only occur as the result
of lose of inherited priority.

  • Property mode set to 100644
File size: 15.9 KB
Line 
1/*  thread.h
2 *
3 *  This include file contains all constants and structures associated
4 *  with the thread control block.
5 *
6 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
7 *  On-Line Applications Research Corporation (OAR).
8 *  All rights assigned to U.S. Government, 1994.
9 *
10 *  This material may be reproduced by or for the U.S. Government pursuant
11 *  to the copyright license under the clause at DFARS 252.227-7013.  This
12 *  notice must appear in all copies of this file and its derivatives.
13 *
14 *  $Id$
15 */
16
17#ifndef __THREAD_h
18#define __THREAD_h
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <rtems/score/context.h>
25#include <rtems/score/cpu.h>
26#include <rtems/score/mppkt.h>
27#include <rtems/score/object.h>
28#include <rtems/score/priority.h>
29#include <rtems/score/stack.h>
30#include <rtems/score/states.h>
31#include <rtems/score/tod.h>
32#include <rtems/score/tqdata.h>
33#include <rtems/score/watchdog.h>
34
35/*
36 *  The following defines the "return type" of a thread.
37 */
38
39typedef void Thread;
40
41/*
42 *  The following defines the ways in which the entry point for a
43 *  thread can be invoked.  Basically, it can be passed any
44 *  combination/permutation of a pointer and an unsigned32 value.
45 *
46 *  NOTE: For now, we are ignoring the return type.
47 */
48
49typedef enum {
50  THREAD_START_NUMERIC,
51  THREAD_START_POINTER,
52  THREAD_START_BOTH_POINTER_FIRST,
53  THREAD_START_BOTH_NUMERIC_FIRST
54} Thread_Start_types;
55
56typedef Thread ( *Thread_Entry )();   /* basic type */
57
58typedef Thread ( *Thread_Entry_numeric )( unsigned32 );
59typedef Thread ( *Thread_Entry_pointer )( void * );
60typedef Thread ( *Thread_Entry_both_pointer_first )( void *, unsigned32 );
61typedef Thread ( *Thread_Entry_both_numeric_first )( unsigned32, void * );
62
63/*
64 *  The following lists the algorithms used to manage the thread cpu budget.
65 *
66 *  Reset Timeslice:   At each context switch, reset the time quantum.
67 *  Exhaust Timeslice: Only reset the quantum once it is consumed.
68 *  Callout:           Execute routine when budget is consumed.
69 */
70
71typedef enum {
72  THREAD_CPU_BUDGET_ALGORITHM_NONE,
73  THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
74  THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
75  THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
76}  Thread_CPU_budget_algorithms;
77
78typedef struct Thread_Control_struct Thread_Control;
79
80typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
81
82/*
83 *  The following structure contains the information which defines
84 *  the starting state of a thread.
85 */
86
87typedef struct {
88  Thread_Entry         entry_point;      /* starting thread address         */
89  Thread_Start_types   prototype;        /* how task is invoked             */
90  void                *pointer_argument; /* pointer argument                */
91  unsigned32           numeric_argument; /* numeric argument                */
92                                         /* initial execution modes         */
93  boolean              is_preemptible;
94  Thread_CPU_budget_algorithms          budget_algorithm;
95  Thread_CPU_budget_algorithm_callout   budget_callout;
96  unsigned32           isr_level;
97  Priority_Control     initial_priority; /* initial priority                */
98  boolean              core_allocated_stack;
99  Stack_Control        Initial_stack;    /* stack information               */
100  void                *fp_context;       /* initial FP context area address */
101  void                *stack;            /* initial FP context area address */
102}   Thread_Start_information;
103
104/*
105 *  The following structure contains the information necessary to manage
106 *  a thread which it is  waiting for a resource.
107 */
108
109#define THREAD_STATUS_PROXY_BLOCKING 0x1111111
110
111typedef struct {
112  Objects_Id            id;              /* waiting on this object       */
113  unsigned32            count;           /* "generic" fields to be used */
114  void                 *return_argument; /*   when blocking */
115  void                 *return_argument_1;
116  unsigned32            option;
117
118  /*
119   *  NOTE: The following assumes that all API return codes can be
120   *        treated as an unsigned32. 
121   */
122  unsigned32            return_code;     /* status for thread awakened   */
123
124  Chain_Control         Block2n;         /* 2 - n priority blocked chain */
125  Thread_queue_Control *queue;           /* pointer to thread queue      */
126}   Thread_Wait_information;
127
128/*
129 *  The following defines the control block used to manage
130 *  each thread proxy.
131 *
132 *  NOTE: It is critical that proxies and threads have identical
133 *        memory images for the shared part.
134 */
135
136typedef struct {
137  Objects_Control          Object;
138  States_Control           current_state;
139  Priority_Control         current_priority;
140  Priority_Control         real_priority;
141  unsigned32               resource_count;
142  Thread_Wait_information  Wait;
143  Watchdog_Control         Timer;
144  MP_packet_Prefix        *receive_packet;
145     /****************** end of common block ********************/
146  Chain_Node               Active;
147}   Thread_Proxy_control;
148
149
150/*
151 *  The following record defines the control block used
152 *  to manage each thread.
153 *
154 *  NOTE: It is critical that proxies and threads have identical
155 *        memory images for the shared part.
156 */
157
158typedef enum {
159  THREAD_API_RTEMS,
160  THREAD_API_POSIX
161}  Thread_APIs;
162
163#define THREAD_API_FIRST THREAD_API_RTEMS
164#define THREAD_API_LAST  THREAD_API_POSIX
165
166struct Thread_Control_struct {
167  Objects_Control                       Object;
168  States_Control                        current_state;
169  Priority_Control                      current_priority;
170  Priority_Control                      real_priority;
171  unsigned32                            resource_count;
172  Thread_Wait_information               Wait;
173  Watchdog_Control                      Timer;
174  MP_packet_Prefix                     *receive_packet;
175     /****************** end of common block ********************/
176  boolean                               is_global;
177  boolean                               do_post_task_switch_extension;
178
179  boolean                               is_preemptible;
180  unsigned32                            cpu_time_budget;
181  Thread_CPU_budget_algorithms          budget_algorithm;
182  Thread_CPU_budget_algorithm_callout   budget_callout;
183
184  unsigned32                            ticks_executed;
185  Chain_Control                        *ready;
186  Priority_Information                  Priority_map;
187  Thread_Start_information              Start;
188  Context_Control                       Registers;
189  void                                 *fp_context;
190  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
191  void                                **extensions;
192};
193
194/*
195 *  The following constants define the stack size requirements for
196 *  the idle thread.
197 */
198 
199 
200#define THREAD_IDLE_STACK_SIZE  STACK_MINIMUM_SIZE
201 
202/*
203 *  The following defines the information control block used to
204 *  manage this class of objects.
205 */
206 
207SCORE_EXTERN Objects_Information _Thread_Internal_information;
208 
209/*
210 *  The following define the thread control pointers used to access
211 *  and manipulate the idle thread.
212 */
213 
214SCORE_EXTERN Thread_Control *_Thread_Idle;
215
216/*
217 *  The following context area contains the context of the "thread"
218 *  which invoked the start multitasking routine.  This context is
219 *  restored as the last action of the stop multitasking routine.  Thus
220 *  control of the processor can be returned to the environment
221 *  which initiated the system.
222 */
223 
224SCORE_EXTERN Context_Control _Thread_BSP_context;
225 
226/*
227 *  The following declares the dispatch critical section nesting
228 *  counter which is used to prevent context switches at inopportune
229 *  moments.
230 */
231
232SCORE_EXTERN unsigned32 _Thread_Dispatch_disable_level;
233
234/*
235 *  If this is non-zero, then the post-task switch extension
236 *  is run regardless of the state of the per thread flag.
237 */
238
239SCORE_EXTERN unsigned32 _Thread_Do_post_task_switch_extension;
240
241/*
242 *  The following holds how many user extensions are in the system.  This
243 *  is used to determine how many user extension data areas to allocate
244 *  per thread.
245 */
246
247SCORE_EXTERN unsigned32 _Thread_Maximum_extensions;
248
249/*
250 *  The following is used to manage the length of a timeslice quantum.
251 */
252
253SCORE_EXTERN unsigned32 _Thread_Ticks_per_timeslice;
254
255/*
256 *  The following points to the array of FIFOs used to manage the
257 *  set of ready threads.
258 */
259
260SCORE_EXTERN Chain_Control *_Thread_Ready_chain;
261
262/*
263 *  The following points to the thread which is currently executing.
264 *  This thread is implicitly manipulated by numerous directives.
265 */
266
267SCORE_EXTERN Thread_Control *_Thread_Executing;
268
269/*
270 *  The following points to the highest priority ready thread
271 *  in the system.  Unless the current thread is not preemptibl,
272 *  then this thread will be context switched to when the next
273 *  dispatch occurs.
274 */
275
276SCORE_EXTERN Thread_Control *_Thread_Heir;
277
278/*
279 *  The following points to the thread whose floating point
280 *  context is currently loaded.
281 */
282
283SCORE_EXTERN Thread_Control *_Thread_Allocated_fp;
284
285/*
286 *  _Thread_Handler_initialization
287 *
288 *  DESCRIPTION:
289 *
290 *  This routine performs the initialization necessary for this handler.
291 */
292
293void _Thread_Handler_initialization (
294  unsigned32   ticks_per_timeslice,
295  unsigned32   maximum_extensions,
296  unsigned32   maximum_proxies
297);
298
299/*
300 *  _Thread_Create_idle
301 *
302 *  DESCRIPTION:
303 *
304 *  This routine creates the idle thread.
305 *
306 *  WARNING!! No thread should be created before this one.
307 */
308 
309void _Thread_Create_idle( void );
310
311/*
312 *  _Thread_Start_multitasking
313 *
314 *  DESCRIPTION:
315 *
316 *  This routine initiates multitasking.  It is invoked only as
317 *  part of initialization and its invocation is the last act of
318 *  the non-multitasking part of the system initialization.
319 */
320
321void _Thread_Start_multitasking( void );
322
323/*
324 *  _Thread_Dispatch
325 *
326 *  DESCRIPTION:
327 *
328 *  This routine is responsible for transferring control of the
329 *  processor from the executing thread to the heir thread.  As part
330 *  of this process, it is responsible for the following actions:
331 *
332 *     + saving the context of the executing thread
333 *     + restoring the context of the heir thread
334 *     + dispatching any signals for the resulting executing thread
335 */
336
337void _Thread_Dispatch( void );
338
339/*
340 *  _Thread_Initialize
341 *
342 *  DESCRIPTION:
343 *
344 *  XXX
345 *
346 *  NOTES:
347 *
348 *  If stack_area is NULL, it is allocated from the workspace.
349 *
350 *  If the stack is allocated from the workspace, then it is guaranteed to be
351 *  of at least minimum size.
352 */
353
354boolean _Thread_Initialize(
355  Objects_Information                  *information,
356  Thread_Control                       *the_thread,
357  void                                 *stack_area,
358  unsigned32                            stack_size,
359  boolean                               is_fp,
360  Priority_Control                      priority,
361  boolean                               is_preemptible,
362  Thread_CPU_budget_algorithms          budget_algorithm,
363  Thread_CPU_budget_algorithm_callout   budget_callout,
364  unsigned32                            isr_level,
365  Objects_Name                          name
366);
367
368/*
369 *  _Thread_Start
370 *
371 *  DESCRIPTION:
372 *
373 *  XXX
374 */
375 
376boolean _Thread_Start(
377  Thread_Control           *the_thread,
378  Thread_Start_types        the_prototype,
379  void                     *entry_point,
380  void                     *pointer_argument,
381  unsigned32                numeric_argument
382);
383
384/*
385 *  _Thread_Restart
386 *
387 *  DESCRIPTION:
388 *
389 *  XXX
390 */
391 
392/* XXX multiple task arg profiles */
393 
394boolean _Thread_Restart(
395  Thread_Control           *the_thread,
396  void                     *pointer_argument,
397  unsigned32                numeric_argument
398);
399
400/*
401 *  _Thread_Close
402 *
403 *  DESCRIPTION:
404 *
405 *  XXX
406 */
407 
408void _Thread_Close(
409  Objects_Information  *information,
410  Thread_Control       *the_thread
411);
412
413/*
414 *  _Thread_Ready
415 *
416 *  DESCRIPTION:
417 *
418 *  This routine removes any set states for the_thread.  It performs
419 *  any necessary scheduling operations including the selection of
420 *  a new heir thread.
421 */
422
423void _Thread_Ready(
424  Thread_Control *the_thread
425);
426
427/*
428 *  _Thread_Clear_state
429 *
430 *  DESCRIPTION:
431 *
432 *  This routine clears the indicated STATES for the_thread.  It performs
433 *  any necessary scheduling operations including the selection of
434 *  a new heir thread.
435 */
436
437void _Thread_Clear_state(
438  Thread_Control *the_thread,
439  States_Control  state
440);
441
442/*
443 *  _Thread_Set_state
444 *
445 *  DESCRIPTION:
446 *
447 *  This routine sets the indicated states for the_thread.  It performs
448 *  any necessary scheduling operations including the selection of
449 *  a new heir thread.
450 *
451 */
452
453void _Thread_Set_state(
454  Thread_Control *the_thread,
455  States_Control  state
456);
457
458/*
459 *  _Thread_Set_transient
460 *
461 *  DESCRIPTION:
462 *
463 *  This routine sets the TRANSIENT state for the_thread.  It performs
464 *  any necessary scheduling operations including the selection of
465 *  a new heir thread.
466 */
467
468void _Thread_Set_transient(
469  Thread_Control *the_thread
470);
471
472/*
473 *  _Thread_Reset_timeslice
474 *
475 *  DESCRIPTION:
476 *
477 *  This routine is invoked upon expiration of the currently
478 *  executing thread's timeslice.  If no other thread's are ready
479 *  at the priority of the currently executing thread, then the
480 *  executing thread's timeslice is reset.  Otherwise, the
481 *  currently executing thread is placed at the rear of the
482 *  FIFO for this priority and a new heir is selected.
483 */
484
485void _Thread_Reset_timeslice( void );
486
487/*
488 *  _Thread_Tickle_timeslice
489 *
490 *  DESCRIPTION:
491 *
492 *  This routine is invoked as part of processing each clock tick.
493 *  It is responsible for determining if the current thread allows
494 *  timeslicing and, if so, when its timeslice expires.
495 */
496
497void _Thread_Tickle_timeslice( void );
498
499/*
500 *  _Thread_Yield_processor
501 *
502 *  DESCRIPTION:
503 *
504 *  This routine is invoked when a thread wishes to voluntarily
505 *  transfer control of the processor to another thread of equal
506 *  or greater priority.
507 */
508
509void _Thread_Yield_processor( void );
510
511/*
512 *  _Thread_Load_environment
513 *
514 *  DESCRIPTION:
515 *
516 *  This routine initializes the context of the_thread to its
517 *  appropriate starting state.
518 */
519
520void _Thread_Load_environment(
521  Thread_Control *the_thread
522);
523
524/*
525 *  _Thread_Handler
526 *
527 *  DESCRIPTION:
528 *
529 *  This routine is the wrapper function for all threads.  It is
530 *  the starting point for all threads.  The user provided thread
531 *  entry point is invoked by this routine.  Operations
532 *  which must be performed immediately before and after the user's
533 *  thread executes are found here.
534 */
535
536void _Thread_Handler( void );
537
538/*
539 *  _Thread_Delay_ended
540 *
541 *  DESCRIPTION:
542 *
543 *  This routine is invoked when a thread must be unblocked at the
544 *  end of a time based delay (i.e. wake after or wake when).
545 */
546
547void _Thread_Delay_ended(
548  Objects_Id  id,
549  void       *ignored
550);
551
552/*
553 *  _Thread_Change_priority
554 *
555 *  DESCRIPTION:
556 *
557 *  This routine changes the current priority of the_thread to
558 *  new_priority.  It performs any necessary scheduling operations
559 *  including the selection of a new heir thread.
560 */
561
562void _Thread_Change_priority (
563  Thread_Control   *the_thread,
564  Priority_Control  new_priority,
565  boolean           prepend_it
566);
567
568/*
569 *  _Thread_Set_priority
570 *
571 *  DESCRIPTION:
572 *
573 *  This routine updates the priority related fields in the_thread
574 *  control block to indicate the current priority is now new_priority.
575 */
576
577void _Thread_Set_priority(
578  Thread_Control   *the_thread,
579  Priority_Control  new_priority
580);
581
582/*
583 *  _Thread_Evaluate_mode
584 *
585 *  DESCRIPTION:
586 *
587 *  This routine XXX
588 */
589
590boolean _Thread_Evaluate_mode( void );
591
592/*
593 *  _Thread_Get
594 *
595 *  NOTE:  If we are not using static inlines, this must be a real
596 *         subroutine call.
597 */
598 
599#ifndef USE_INLINES
600Thread_Control *_Thread_Get (
601  Objects_Id           id,
602  Objects_Locations   *location
603);
604#endif
605
606/*
607 *  _Thread_Idle_body
608 *
609 *  DESCRIPTION:
610 *
611 *  This routine is the body of the system idle thread.
612 */
613 
614#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
615Thread _Thread_Idle_body(
616  unsigned32 ignored
617);
618#endif
619
620#ifndef __RTEMS_APPLICATION__
621#include <rtems/score/thread.inl>
622#endif
623#include <rtems/score/threadmp.h>
624
625#ifdef __cplusplus
626}
627#endif
628
629#endif
630/* end of include file */
Note: See TracBrowser for help on using the repository browser.