source: rtems/cpukit/score/src/threadhandler.c @ a8e030d

4.104.114.84.95
Last change on this file since a8e030d was a8e030d, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 28, 2007 at 2:09:37 PM

2007-08-28 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems/rtems/clock.h, score/src/threadhandler.c: Fix spacing and spelling.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/apiext.h>
21#include <rtems/score/context.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/object.h>
25#include <rtems/score/priority.h>
26#include <rtems/score/states.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32
33/*PAGE
34 *
35 *  _Thread_Handler
36 *
37 *  This routine is the "primal" entry point for all threads.
38 *  _Context_Initialize() dummies up the thread's initial context
39 *  to cause the first Context_Switch() to jump to _Thread_Handler().
40 *
41 *  This routine is the default thread exitted error handler.  It is
42 *  returned to when a thread exits.  The configured fatal error handler
43 *  is invoked to process the exit.
44 *
45 *  NOTE:
46 *
47 *  On entry, it is assumed all interrupts are blocked and that this
48 *  routine needs to set the initial isr level.  This may or may not
49 *  actually be needed by the context switch routine and as a result
50 *  interrupts may already be at there proper level.  Either way,
51 *  setting the initial isr level properly here is safe.
52 *
53 *  Currently this is only really needed for the posix port,
54 *  ref: _Context_Switch in unix/cpu.c
55 *
56 *  Input parameters:   NONE
57 *
58 *  Output parameters:  NONE
59 */
60
61void _Thread_Handler( void )
62{
63  ISR_Level  level;
64  Thread_Control *executing;
65#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
66  static char doneConstructors;
67  char doneCons;
68#endif
69#if defined(__USE_INIT_FINI__)
70  extern void _init(void);
71#endif
72#if defined(__USE__MAIN__)
73  extern void _main(void);
74#endif
75
76  executing = _Thread_Executing;
77
78  /*
79   * have to put level into a register for those cpu's that use
80   * inline asm here
81   */
82
83  level = executing->Start.isr_level;
84  _ISR_Set_level(level);
85
86#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
87  doneCons = doneConstructors;
88  doneConstructors = 1;
89#endif
90
91#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
92#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
93  if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) {
94    if ( _Thread_Allocated_fp != NULL )
95      _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
96    _Thread_Allocated_fp = executing;
97  }
98#endif
99#endif
100
101  /*
102   * Take care that 'begin' extensions get to complete before
103   * 'switch' extensions can run.  This means must keep dispatch
104   * disabled until all 'begin' extensions complete.
105   */
106
107  _User_extensions_Thread_begin( executing );
108
109  /*
110   *  At this point, the dispatch disable level BETTER be 1.
111   */
112
113  _Thread_Enable_dispatch();
114#if defined(__USE_INIT_FINI__)
115  /*
116   *  _init could be a weak symbol and we SHOULD test it but it isn't
117   *  in any configuration I know of and it generates a warning on every
118   *  RTEMS target configuration.  --joel (12 May 2007)
119   */
120  if (!doneCons) /* && (volatile void *)_init) */
121    _init ();
122#endif
123#if defined(__USE__MAIN__)
124  if (!doneCons && _main)
125    __main ();
126#endif
127
128  switch ( executing->Start.prototype ) {
129    case THREAD_START_NUMERIC:
130      executing->Wait.return_argument =
131        (*(Thread_Entry_numeric) executing->Start.entry_point)(
132          executing->Start.numeric_argument
133      );
134      break;
135    case THREAD_START_POINTER:
136      executing->Wait.return_argument =
137        (*(Thread_Entry_pointer) executing->Start.entry_point)(
138          executing->Start.pointer_argument
139        );
140      break;
141    case THREAD_START_BOTH_POINTER_FIRST:
142      executing->Wait.return_argument =
143         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
144           executing->Start.pointer_argument,
145           executing->Start.numeric_argument
146         );
147      break;
148    case THREAD_START_BOTH_NUMERIC_FIRST:
149      executing->Wait.return_argument =
150         (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
151           executing->Start.numeric_argument,
152           executing->Start.pointer_argument
153         );
154      break;
155  }
156
157  /*
158   *  In the switch above, the return code from the user thread body
159   *  was placed in return_argument.  This assumed that if it returned
160   *  anything (which is not supporting in all APIs), then it would be
161   *  able to fit in a (void *).
162   */
163
164  _User_extensions_Thread_exitted( executing );
165
166  _Internal_error_Occurred(
167    INTERNAL_ERROR_CORE,
168    TRUE,
169    INTERNAL_ERROR_THREAD_EXITTED
170  );
171}
Note: See TracBrowser for help on using the repository browser.