source: rtems/cpukit/score/src/threadhandler.c @ 8f0529f

4.104.114.84.95
Last change on this file since 8f0529f was 260b0c2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/30/99 at 18:05:48

Patch from Charles-Antoine Gauthier <charles.gauthier@…> to add
support for return codes from POSIX threads that do an implicit exit
by returning from the bottom of the main function.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/score/apiext.h>
18#include <rtems/score/context.h>
19#include <rtems/score/interr.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/object.h>
22#include <rtems/score/priority.h>
23#include <rtems/score/states.h>
24#include <rtems/score/sysstate.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/threadq.h>
27#include <rtems/score/userext.h>
28#include <rtems/score/wkspace.h>
29
30/*PAGE
31 *
32 *  _Thread_Handler
33 *
34 *  This routine is the "primal" entry point for all threads.
35 *  _Context_Initialize() dummies up the thread's initial context
36 *  to cause the first Context_Switch() to jump to _Thread_Handler().
37 *
38 *  This routine is the default thread exitted error handler.  It is
39 *  returned to when a thread exits.  The configured fatal error handler
40 *  is invoked to process the exit.
41 *
42 *  NOTE:
43 *
44 *  On entry, it is assumed all interrupts are blocked and that this
45 *  routine needs to set the initial isr level.  This may or may not
46 *  actually be needed by the context switch routine and as a result
47 *  interrupts may already be at there proper level.  Either way,
48 *  setting the initial isr level properly here is safe.
49 * 
50 *  Currently this is only really needed for the posix port,
51 *  ref: _Context_Switch in unix/cpu.c
52 *
53 *  Input parameters:   NONE
54 *
55 *  Output parameters:  NONE
56 */
57
58void _Thread_Handler( void )
59{
60  ISR_Level  level;
61  Thread_Control *executing;
62 
63  executing = _Thread_Executing;
64 
65  /*
66   * have to put level into a register for those cpu's that use
67   * inline asm here
68   */
69 
70  level = executing->Start.isr_level;
71  _ISR_Set_level(level);
72
73  /*
74   * Take care that 'begin' extensions get to complete before
75   * 'switch' extensions can run.  This means must keep dispatch
76   * disabled until all 'begin' extensions complete.
77   */
78 
79  _User_extensions_Thread_begin( executing );
80 
81  /*
82   *  At this point, the dispatch disable level BETTER be 1.
83   */
84
85  _Thread_Enable_dispatch();
86 
87  switch ( executing->Start.prototype ) {
88    case THREAD_START_NUMERIC:
89      executing->Wait.return_argument =
90        (*(Thread_Entry_numeric) executing->Start.entry_point)(
91          executing->Start.numeric_argument
92      );
93      break;
94    case THREAD_START_POINTER:
95      executing->Wait.return_argument =
96        (*(Thread_Entry_pointer) executing->Start.entry_point)(
97          executing->Start.pointer_argument
98        );
99      break;
100    case THREAD_START_BOTH_POINTER_FIRST:
101      executing->Wait.return_argument =
102         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
103           executing->Start.pointer_argument,
104           executing->Start.numeric_argument
105         );
106      break;
107    case THREAD_START_BOTH_NUMERIC_FIRST:
108      executing->Wait.return_argument =
109         (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
110           executing->Start.numeric_argument,
111           executing->Start.pointer_argument
112         );
113      break;
114  }
115
116  /*
117   *  In the switch above, the return code from the user thread body
118   *  was placed in return_argument.  This assumed that if it returned
119   *  anything (which is not supporting in all APIs), then it would be
120   *  able to fit in a (void *).
121   */
122
123  _User_extensions_Thread_exitted( executing );
124
125  _Internal_error_Occurred(
126    INTERNAL_ERROR_CORE,
127    TRUE,
128    INTERNAL_ERROR_THREAD_EXITTED
129  );
130}
Note: See TracBrowser for help on using the repository browser.