source: rtems/cpukit/score/include/rtems/score/thread.h @ dcc1f6b6

4.104.114.84.95
Last change on this file since dcc1f6b6 was 352c9b2, checked in by Joel Sherrill <joel.sherrill@…>, on 11/09/99 at 22:07:23

This patch adds the basic framework for the ITRON 3.0 API implementation
for RTEMS.

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