source: rtems/cpukit/score/include/rtems/score/thread.h @ 97e2729d

4.104.114.84.95
Last change on this file since 97e2729d was 97e2729d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 17:38:09

Added --disable-multiprocessing flag and modified a lot of files to make
it work.

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