source: rtems/cpukit/score/src/threadhandler.c @ 5a58b1e

4.115
Last change on this file since 5a58b1e was 5a58b1e, checked in by Daniel Georgiev <daniel.georgiev95@…>, on 12/01/12 at 14:53:45

score misc: Score misc: Clean up Doxygen #11 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/8013204

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Thread Handler
5 *  @ingroup ScoreThread
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2012.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/score/apiext.h>
23#include <rtems/score/context.h>
24#include <rtems/score/interr.h>
25#include <rtems/score/isr.h>
26#include <rtems/score/object.h>
27#include <rtems/score/priority.h>
28#include <rtems/score/states.h>
29#include <rtems/score/sysstate.h>
30#include <rtems/score/thread.h>
31#include <rtems/score/threadq.h>
32#include <rtems/score/userextimpl.h>
33#include <rtems/score/wkspace.h>
34#if defined(RTEMS_SMP)
35  #include <rtems/score/smp.h>
36#endif
37
38/*
39 *  Conditional magic to determine what style of C++ constructor
40 *  initialization this target and compiler version uses.
41 */
42#if defined(__USE_INIT_FINI__)
43  #if defined(__M32R__)
44    #define INIT_NAME __init
45  #elif defined(__ARM_EABI__)
46    #define INIT_NAME __libc_init_array
47  #else
48    #define INIT_NAME _init
49  #endif
50
51  extern void INIT_NAME(void);
52  #define EXECUTE_GLOBAL_CONSTRUCTORS
53#endif
54
55#if defined(__USE__MAIN__)
56  extern void __main(void);
57  #define INIT_NAME __main
58  #define EXECUTE_GLOBAL_CONSTRUCTORS
59#endif
60
61void _Thread_Handler( void )
62{
63  ISR_Level  level;
64  Thread_Control *executing;
65  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
66    static bool doneConstructors;
67    bool doCons;
68  #endif
69
70  executing = _Thread_Executing;
71
72  /*
73   * Some CPUs need to tinker with the call frame or registers when the
74   * thread actually begins to execute for the first time.  This is a
75   * hook point where the port gets a shot at doing whatever it requires.
76   */
77  _Context_Initialization_at_thread_begin();
78
79  /*
80   * have to put level into a register for those cpu's that use
81   * inline asm here
82   */
83  level = executing->Start.isr_level;
84  _ISR_Set_level(level);
85
86  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
87    #if defined(RTEMS_MULTIPROCESSING)
88      doCons = !doneConstructors
89        && _Objects_Get_API( executing->Object.id ) != OBJECTS_INTERNAL_API;
90      if (doCons)
91        doneConstructors = true;
92    #else
93      doCons = !doneConstructors;
94      doneConstructors = true;
95    #endif
96  #endif
97
98  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
99    #if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
100      if ( (executing->fp_context != NULL) &&
101            !_Thread_Is_allocated_fp( executing ) ) {
102        if ( _Thread_Allocated_fp != NULL )
103          _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
104        _Thread_Allocated_fp = executing;
105      }
106    #endif
107  #endif
108
109  /*
110   * Take care that 'begin' extensions get to complete before
111   * 'switch' extensions can run.  This means must keep dispatch
112   * disabled until all 'begin' extensions complete.
113   */
114  _User_extensions_Thread_begin( executing );
115
116  /*
117   *  At this point, the dispatch disable level BETTER be 1.
118   */
119  _Thread_Enable_dispatch();
120
121  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
122    /*
123     *  _init could be a weak symbol and we SHOULD test it but it isn't
124     *  in any configuration I know of and it generates a warning on every
125     *  RTEMS target configuration.  --joel (12 May 2007)
126     */
127    if (doCons) /* && (volatile void *)_init) */ {
128      INIT_NAME ();
129   
130      #if defined(RTEMS_SMP)
131        _Thread_Disable_dispatch();
132          _SMP_Request_other_cores_to_perform_first_context_switch();
133        _Thread_Enable_dispatch();
134      #endif
135    }
136 #endif
137
138  if ( executing->Start.prototype == THREAD_START_NUMERIC ) {
139    executing->Wait.return_argument =
140      (*(Thread_Entry_numeric) executing->Start.entry_point)(
141        executing->Start.numeric_argument
142      );
143  }
144  #if defined(RTEMS_POSIX_API)
145    else if ( executing->Start.prototype == THREAD_START_POINTER ) {
146      executing->Wait.return_argument =
147        (*(Thread_Entry_pointer) executing->Start.entry_point)(
148          executing->Start.pointer_argument
149        );
150    }
151  #endif
152  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
153    else if ( executing->Start.prototype == THREAD_START_BOTH_POINTER_FIRST ) {
154      executing->Wait.return_argument =
155         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
156           executing->Start.pointer_argument,
157           executing->Start.numeric_argument
158         );
159    }
160    else if ( executing->Start.prototype == THREAD_START_BOTH_NUMERIC_FIRST ) {
161      executing->Wait.return_argument =
162       (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
163         executing->Start.numeric_argument,
164         executing->Start.pointer_argument
165       );
166    }
167  #endif
168
169  /*
170   *  In the switch above, the return code from the user thread body
171   *  was placed in return_argument.  This assumed that if it returned
172   *  anything (which is not supporting in all APIs), then it would be
173   *  able to fit in a (void *).
174   */
175
176  _User_extensions_Thread_exitted( executing );
177
178  _Internal_error_Occurred(
179    INTERNAL_ERROR_CORE,
180    true,
181    INTERNAL_ERROR_THREAD_EXITTED
182  );
183}
Note: See TracBrowser for help on using the repository browser.