source: rtems/cpukit/score/include/rtems/score/thread.h @ 1b17790c

4.104.114.84.95
Last change on this file since 1b17790c was 1b17790c, checked in by Joel Sherrill <joel.sherrill@…>, on 06/13/96 at 16:43:39

Added code so post context switch extensions can be run on every context
switch. This was needed to support process wide signals.

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