source: rtems/cpukit/score/include/rtems/score/thread.h @ 847375f

4.104.114.84.95
Last change on this file since 847375f was 847375f, checked in by Joel Sherrill <joel.sherrill@…>, on 11/19/98 at 17:35:49

Patch from Eric Norum <eric@…>:

1) Socket timeout field changed from short' to long'. This makes longer

timeouts possible. With a 1 kHz system clock the old system allowed
timeouts only up to a little over 30 seconds! This change is a
slightly cleaned-up version of the patch proposed by Ian Lance Taylor.

2) Major changes to BOOTP/DHCP reply handling. Now supports much of

RFC2132. These changes were done at the request of, and with the
assistance of, Erik Ivanenko.

If you're making changes, you might want to change the network
supplement Essentially just do a global search and replace of BOOTP
with BOOTP/DHCP.

  • Property mode set to 100644
File size: 15.8 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#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 stack 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  void                                 *rtems_ada_self;
181  unsigned32                            cpu_time_budget;
182  Thread_CPU_budget_algorithms          budget_algorithm;
183  Thread_CPU_budget_algorithm_callout   budget_callout;
184
185  unsigned32                            ticks_executed;
186  Chain_Control                        *ready;
187  Priority_Information                  Priority_map;
188  Thread_Start_information              Start;
189  Context_Control                       Registers;
190  void                                 *fp_context;
191  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
192  void                                **extensions;
193};
194
195/*
196 *  Self for the GNU Ada Run-Time
197 */
198
199SCORE_EXTERN void *rtems_ada_self;
200 
201/*
202 *  The following defines the information control block used to
203 *  manage this class of objects.
204 */
205 
206SCORE_EXTERN Objects_Information _Thread_Internal_information;
207 
208/*
209 *  The following define the thread control pointers used to access
210 *  and manipulate the idle thread.
211 */
212 
213SCORE_EXTERN Thread_Control *_Thread_Idle;
214
215/*
216 *  The following context area contains the context of the "thread"
217 *  which invoked the start multitasking routine.  This context is
218 *  restored as the last action of the stop multitasking routine.  Thus
219 *  control of the processor can be returned to the environment
220 *  which initiated the system.
221 */
222 
223SCORE_EXTERN Context_Control _Thread_BSP_context;
224 
225/*
226 *  The following declares the dispatch critical section nesting
227 *  counter which is used to prevent context switches at inopportune
228 *  moments.
229 */
230
231SCORE_EXTERN unsigned32 _Thread_Dispatch_disable_level;
232
233/*
234 *  If this is non-zero, then the post-task switch extension
235 *  is run regardless of the state of the per thread flag.
236 */
237
238SCORE_EXTERN unsigned32 _Thread_Do_post_task_switch_extension;
239
240/*
241 *  The following holds how many user extensions are in the system.  This
242 *  is used to determine how many user extension data areas to allocate
243 *  per thread.
244 */
245
246SCORE_EXTERN unsigned32 _Thread_Maximum_extensions;
247
248/*
249 *  The following is used to manage the length of a timeslice quantum.
250 */
251
252SCORE_EXTERN unsigned32 _Thread_Ticks_per_timeslice;
253
254/*
255 *  The following points to the array of FIFOs used to manage the
256 *  set of ready threads.
257 */
258
259SCORE_EXTERN Chain_Control *_Thread_Ready_chain;
260
261/*
262 *  The following points to the thread which is currently executing.
263 *  This thread is implicitly manipulated by numerous directives.
264 */
265
266SCORE_EXTERN Thread_Control *_Thread_Executing;
267
268/*
269 *  The following points to the highest priority ready thread
270 *  in the system.  Unless the current thread is not preemptibl,
271 *  then this thread will be context switched to when the next
272 *  dispatch occurs.
273 */
274
275SCORE_EXTERN Thread_Control *_Thread_Heir;
276
277/*
278 *  The following points to the thread whose floating point
279 *  context is currently loaded.
280 */
281
282SCORE_EXTERN Thread_Control *_Thread_Allocated_fp;
283
284/*
285 *  _Thread_Handler_initialization
286 *
287 *  DESCRIPTION:
288 *
289 *  This routine performs the initialization necessary for this handler.
290 */
291
292void _Thread_Handler_initialization (
293  unsigned32   ticks_per_timeslice,
294  unsigned32   maximum_extensions,
295  unsigned32   maximum_proxies
296);
297
298/*
299 *  _Thread_Create_idle
300 *
301 *  DESCRIPTION:
302 *
303 *  This routine creates the idle thread.
304 *
305 *  WARNING!! No thread should be created before this one.
306 */
307 
308void _Thread_Create_idle( void );
309
310/*
311 *  _Thread_Start_multitasking
312 *
313 *  DESCRIPTION:
314 *
315 *  This routine initiates multitasking.  It is invoked only as
316 *  part of initialization and its invocation is the last act of
317 *  the non-multitasking part of the system initialization.
318 */
319
320void _Thread_Start_multitasking( void );
321
322/*
323 *  _Thread_Dispatch
324 *
325 *  DESCRIPTION:
326 *
327 *  This routine is responsible for transferring control of the
328 *  processor from the executing thread to the heir thread.  As part
329 *  of this process, it is responsible for the following actions:
330 *
331 *     + saving the context of the executing thread
332 *     + restoring the context of the heir thread
333 *     + dispatching any signals for the resulting executing thread
334 */
335
336void _Thread_Dispatch( void );
337
338/*
339 *  _Thread_Initialize
340 *
341 *  DESCRIPTION:
342 *
343 *  XXX
344 *
345 *  NOTES:
346 *
347 *  If stack_area is NULL, it is allocated from the workspace.
348 *
349 *  If the stack is allocated from the workspace, then it is guaranteed to be
350 *  of at least minimum size.
351 */
352
353boolean _Thread_Initialize(
354  Objects_Information                  *information,
355  Thread_Control                       *the_thread,
356  void                                 *stack_area,
357  unsigned32                            stack_size,
358  boolean                               is_fp,
359  Priority_Control                      priority,
360  boolean                               is_preemptible,
361  Thread_CPU_budget_algorithms          budget_algorithm,
362  Thread_CPU_budget_algorithm_callout   budget_callout,
363  unsigned32                            isr_level,
364  Objects_Name                          name
365);
366
367/*
368 *  _Thread_Start
369 *
370 *  DESCRIPTION:
371 *
372 *  XXX
373 */
374 
375boolean _Thread_Start(
376  Thread_Control           *the_thread,
377  Thread_Start_types        the_prototype,
378  void                     *entry_point,
379  void                     *pointer_argument,
380  unsigned32                numeric_argument
381);
382
383/*
384 *  _Thread_Restart
385 *
386 *  DESCRIPTION:
387 *
388 *  XXX
389 */
390 
391/* XXX multiple task arg profiles */
392 
393boolean _Thread_Restart(
394  Thread_Control           *the_thread,
395  void                     *pointer_argument,
396  unsigned32                numeric_argument
397);
398
399/*
400 *  _Thread_Close
401 *
402 *  DESCRIPTION:
403 *
404 *  XXX
405 */
406 
407void _Thread_Close(
408  Objects_Information  *information,
409  Thread_Control       *the_thread
410);
411
412/*
413 *  _Thread_Ready
414 *
415 *  DESCRIPTION:
416 *
417 *  This routine removes any set states for the_thread.  It performs
418 *  any necessary scheduling operations including the selection of
419 *  a new heir thread.
420 */
421
422void _Thread_Ready(
423  Thread_Control *the_thread
424);
425
426/*
427 *  _Thread_Clear_state
428 *
429 *  DESCRIPTION:
430 *
431 *  This routine clears the indicated STATES for the_thread.  It performs
432 *  any necessary scheduling operations including the selection of
433 *  a new heir thread.
434 */
435
436void _Thread_Clear_state(
437  Thread_Control *the_thread,
438  States_Control  state
439);
440
441/*
442 *  _Thread_Set_state
443 *
444 *  DESCRIPTION:
445 *
446 *  This routine sets the indicated states for the_thread.  It performs
447 *  any necessary scheduling operations including the selection of
448 *  a new heir thread.
449 *
450 */
451
452void _Thread_Set_state(
453  Thread_Control *the_thread,
454  States_Control  state
455);
456
457/*
458 *  _Thread_Set_transient
459 *
460 *  DESCRIPTION:
461 *
462 *  This routine sets the TRANSIENT state for the_thread.  It performs
463 *  any necessary scheduling operations including the selection of
464 *  a new heir thread.
465 */
466
467void _Thread_Set_transient(
468  Thread_Control *the_thread
469);
470
471/*
472 *  _Thread_Reset_timeslice
473 *
474 *  DESCRIPTION:
475 *
476 *  This routine is invoked upon expiration of the currently
477 *  executing thread's timeslice.  If no other thread's are ready
478 *  at the priority of the currently executing thread, then the
479 *  executing thread's timeslice is reset.  Otherwise, the
480 *  currently executing thread is placed at the rear of the
481 *  FIFO for this priority and a new heir is selected.
482 */
483
484void _Thread_Reset_timeslice( void );
485
486/*
487 *  _Thread_Tickle_timeslice
488 *
489 *  DESCRIPTION:
490 *
491 *  This routine is invoked as part of processing each clock tick.
492 *  It is responsible for determining if the current thread allows
493 *  timeslicing and, if so, when its timeslice expires.
494 */
495
496void _Thread_Tickle_timeslice( void );
497
498/*
499 *  _Thread_Yield_processor
500 *
501 *  DESCRIPTION:
502 *
503 *  This routine is invoked when a thread wishes to voluntarily
504 *  transfer control of the processor to another thread of equal
505 *  or greater priority.
506 */
507
508void _Thread_Yield_processor( void );
509
510/*
511 *  _Thread_Load_environment
512 *
513 *  DESCRIPTION:
514 *
515 *  This routine initializes the context of the_thread to its
516 *  appropriate starting state.
517 */
518
519void _Thread_Load_environment(
520  Thread_Control *the_thread
521);
522
523/*
524 *  _Thread_Handler
525 *
526 *  DESCRIPTION:
527 *
528 *  This routine is the wrapper function for all threads.  It is
529 *  the starting point for all threads.  The user provided thread
530 *  entry point is invoked by this routine.  Operations
531 *  which must be performed immediately before and after the user's
532 *  thread executes are found here.
533 */
534
535void _Thread_Handler( void );
536
537/*
538 *  _Thread_Delay_ended
539 *
540 *  DESCRIPTION:
541 *
542 *  This routine is invoked when a thread must be unblocked at the
543 *  end of a time based delay (i.e. wake after or wake when).
544 */
545
546void _Thread_Delay_ended(
547  Objects_Id  id,
548  void       *ignored
549);
550
551/*
552 *  _Thread_Change_priority
553 *
554 *  DESCRIPTION:
555 *
556 *  This routine changes the current priority of the_thread to
557 *  new_priority.  It performs any necessary scheduling operations
558 *  including the selection of a new heir thread.
559 */
560
561void _Thread_Change_priority (
562  Thread_Control   *the_thread,
563  Priority_Control  new_priority,
564  boolean           prepend_it
565);
566
567/*
568 *  _Thread_Set_priority
569 *
570 *  DESCRIPTION:
571 *
572 *  This routine updates the priority related fields in the_thread
573 *  control block to indicate the current priority is now new_priority.
574 */
575
576void _Thread_Set_priority(
577  Thread_Control   *the_thread,
578  Priority_Control  new_priority
579);
580
581/*
582 *  _Thread_Evaluate_mode
583 *
584 *  DESCRIPTION:
585 *
586 *  This routine XXX
587 */
588
589boolean _Thread_Evaluate_mode( void );
590
591/*
592 *  _Thread_Get
593 *
594 *  NOTE:  If we are not using static inlines, this must be a real
595 *         subroutine call.
596 */
597 
598#ifndef USE_INLINES
599Thread_Control *_Thread_Get (
600  Objects_Id           id,
601  Objects_Locations   *location
602);
603#endif
604
605/*
606 *  _Thread_Idle_body
607 *
608 *  DESCRIPTION:
609 *
610 *  This routine is the body of the system idle thread.
611 */
612 
613#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
614Thread _Thread_Idle_body(
615  unsigned32 ignored
616);
617#endif
618
619#ifndef __RTEMS_APPLICATION__
620#include <rtems/score/thread.inl>
621#endif
622#include <rtems/score/threadmp.h>
623
624#ifdef __cplusplus
625}
626#endif
627
628#endif
629/* end of include file */
Note: See TracBrowser for help on using the repository browser.