source: rtems/cpukit/score/inline/rtems/score/thread.inl @ 8e2cd0c

4.104.115
Last change on this file since 8e2cd0c was 8e2cd0c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/25/09 at 18:08:55

2009-09-25 Joel Sherrill <joel.sherrill@…>

  • score/inline/rtems/score/thread.inl: Restore the BSP context -- do not save the current. This routine is also marked as not returning which saves the exit path code.
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/**
2 *  @file  rtems/score/thread.inl
3 *
4 *  This file contains the macro implementation of the inlined
5 *  routines from the Thread handler.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
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 *  $Id$
17 */
18
19#ifndef _RTEMS_SCORE_THREAD_H
20# error "Never use <rtems/score/thread.inl> directly; include <rtems/score/thread.h> instead."
21#endif
22
23#ifndef _RTEMS_SCORE_THREAD_INL
24#define _RTEMS_SCORE_THREAD_INL
25
26#include <rtems/score/sysstate.h>
27#include <rtems/score/context.h>
28
29/**
30 *  @addtogroup ScoreThread
31 *  @{
32 */
33
34/**
35 *  This routine halts multitasking and returns control to
36 *  the "thread" (i.e. the BSP) which initially invoked the
37 *  routine which initialized the system.
38 */
39
40RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void )
41{
42  Context_Control context_area;
43  Context_Control *context_p = &context_area;
44
45  if ( _System_state_Is_up(_System_state_Get ()) )
46    context_p = &_Thread_Executing->Registers;
47
48  /*
49   *  This may look a bit of an odd but _Context_Restart_self is just
50   *  a very careful restore of a specific context which ensures that
51   *  if we were running within the same context, it would work.
52   *
53   *  And we will not return to this thread, so there is no point of
54   *  saving the context.
55   */
56  _Context_Restart_self( &_Thread_BSP_context );
57
58  /***************************************************************
59   ***************************************************************
60   *   SYSTEM SHUTS DOWN!!!  WE DO NOT RETURN TO THIS POINT!!!   *
61   ***************************************************************
62   ***************************************************************
63   */
64}
65
66/**
67 *  This function returns true if the_thread is the currently executing
68 *  thread, and false otherwise.
69 */
70
71RTEMS_INLINE_ROUTINE bool _Thread_Is_executing (
72  const Thread_Control *the_thread
73)
74{
75  return ( the_thread == _Thread_Executing );
76}
77
78/**
79 *  This function returns true if the_thread is the heir
80 *  thread, and false otherwise.
81 */
82
83RTEMS_INLINE_ROUTINE bool _Thread_Is_heir (
84  const Thread_Control *the_thread
85)
86{
87  return ( the_thread == _Thread_Heir );
88}
89
90/**
91 *  This function returns true if the currently executing thread
92 *  is also the heir thread, and false otherwise.
93 */
94
95RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_also_the_heir( void )
96{
97  return ( _Thread_Executing == _Thread_Heir );
98}
99
100/**
101 *  This routine clears any blocking state for the_thread.  It performs
102 *  any necessary scheduling operations including the selection of
103 *  a new heir thread.
104 */
105
106RTEMS_INLINE_ROUTINE void _Thread_Unblock (
107  Thread_Control *the_thread
108)
109{
110  _Thread_Clear_state( the_thread, STATES_BLOCKED );
111}
112
113/**
114 *  This routine resets the current context of the calling thread
115 *  to that of its initial state.
116 */
117
118RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void )
119{
120#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
121  if ( _Thread_Executing->fp_context != NULL )
122    _Context_Restore_fp( &_Thread_Executing->fp_context );
123#endif
124
125  _CPU_Context_Restart_self( &_Thread_Executing->Registers );
126}
127
128/**
129 *  This function returns a pointer to the highest priority
130 *  ready thread.
131 */
132
133RTEMS_INLINE_ROUTINE void _Thread_Calculate_heir( void )
134{
135  _Thread_Heir = (Thread_Control *)
136    _Thread_Ready_chain[ _Priority_Get_highest() ].first;
137}
138
139/**
140 *  This function returns true if the floating point context of
141 *  the_thread is currently loaded in the floating point unit, and
142 *  false otherwise.
143 */
144
145#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
146RTEMS_INLINE_ROUTINE bool _Thread_Is_allocated_fp (
147  const Thread_Control *the_thread
148)
149{
150  return ( the_thread == _Thread_Allocated_fp );
151}
152#endif
153
154/**
155 *  This routine is invoked when the currently loaded floating
156 *  point context is now longer associated with an active thread.
157 */
158
159#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
160RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void )
161{
162  _Thread_Allocated_fp = NULL;
163}
164#endif
165
166/**
167 *  This routine prevents dispatching.
168 */
169
170#if defined(RTEMS_HEAVY_STACK_DEBUG) || defined(RTEMS_HEAVY_MALLOC_DEBUG)
171  #include <rtems/bspIo.h>
172  #include <rtems/fatal.h>
173  #include <rtems/stackchk.h>
174  #include <rtems/score/sysstate.h>
175  #include <rtems/score/heap.h>
176
177  /*
178   * This is currently not defined in any .h file, so we have to
179   * extern it here.
180   */
181  extern Heap_Control  *RTEMS_Malloc_Heap;
182#endif
183
184RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
185{
186  /*
187   *  This check is very brutal to system performance but is very helpful
188   *  at finding blown stack problems.  If you have a stack problem and
189   *  need help finding it, then uncomment this code.  Every system
190   *  call will check the stack and since mutexes are used frequently
191   *  in most systems, you might get lucky.
192   */
193  #if defined(RTEMS_HEAVY_STACK_DEBUG)
194    if (_System_state_Is_up(_System_state_Get()) && (_ISR_Nest_level == 0)) {
195      if ( rtems_stack_checker_is_blown() ) {
196        printk( "Stack blown!!\n" );
197        rtems_fatal_error_occurred( 99 );
198      }
199    }
200  #endif
201
202  _Thread_Dispatch_disable_level += 1;
203  RTEMS_COMPILER_MEMORY_BARRIER();
204
205  /*
206   * This check is even more brutal than the other one.  This enables
207   * malloc heap integrity checking upon entry to every system call.
208   */
209  #if defined(RTEMS_HEAVY_MALLOC_DEBUG)
210    if ( _Thread_Dispatch_disable_level == 1 ) {
211      _Heap_Walk( RTEMS_Malloc_Heap,99, false );
212    }
213  #endif
214}
215
216/**
217 *  This routine allows dispatching to occur again.  If this is
218 *  the outer most dispatching critical section, then a dispatching
219 *  operation will be performed and, if necessary, control of the
220 *  processor will be transferred to the heir thread.
221 */
222
223#if ( (CPU_INLINE_ENABLE_DISPATCH == FALSE) || \
224      (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1) )
225void _Thread_Enable_dispatch( void );
226#else
227/* inlining of enable dispatching must be true */
228RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch( void )
229{
230  RTEMS_COMPILER_MEMORY_BARRIER();
231  if ( (--_Thread_Dispatch_disable_level) == 0 )
232    _Thread_Dispatch();
233}
234#endif
235
236
237/**
238 *  This routine allows dispatching to occur again.  However,
239 *  no dispatching operation is performed even if this is the outer
240 *  most dispatching critical section.
241 */
242
243RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void )
244{
245  RTEMS_COMPILER_MEMORY_BARRIER();
246  _Thread_Dispatch_disable_level -= 1;
247}
248
249/**
250 *  This function returns true if dispatching is disabled, and false
251 *  otherwise.
252 */
253
254RTEMS_INLINE_ROUTINE bool _Thread_Is_dispatching_enabled( void )
255{
256  return ( _Thread_Dispatch_disable_level == 0 );
257}
258
259/**
260 *  This function returns true if dispatching is disabled, and false
261 *  otherwise.
262 */
263
264RTEMS_INLINE_ROUTINE bool _Thread_Is_context_switch_necessary( void )
265{
266  return ( _Context_Switch_necessary );
267}
268
269/**
270 *  This routine initializes the thread dispatching subsystem.
271 */
272
273RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
274{
275  _Thread_Dispatch_disable_level = 1;
276}
277
278/**
279 *  This function returns true if the_thread is NULL and false otherwise.
280 */
281
282RTEMS_INLINE_ROUTINE bool _Thread_Is_null (
283  const Thread_Control *the_thread
284)
285{
286  return ( the_thread == NULL );
287}
288
289/** @brief _Thread_Is_proxy_blocking
290 *
291 *  status which indicates that a proxy is blocking, and false otherwise.
292 */
293RTEMS_INLINE_ROUTINE bool _Thread_Is_proxy_blocking (
294  uint32_t   code
295)
296{
297  return (code == THREAD_STATUS_PROXY_BLOCKING);
298}
299
300/**
301 *  This routine allocates an internal thread.
302 */
303 
304RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
305{
306  return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
307}
308 
309/**
310 *  This routine frees an internal thread.
311 */
312 
313RTEMS_INLINE_ROUTINE void _Thread_Internal_free (
314  Thread_Control *the_task
315)
316{
317  _Objects_Free( &_Thread_Internal_information, &the_task->Object );
318}
319
320/**
321 *  This routine returns the C library re-enterant pointer.
322 */
323 
324RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void )
325{
326  return _Thread_libc_reent;
327}
328
329/**
330 *  This routine set the C library re-enterant pointer.
331 */
332 
333RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent (
334  struct _reent **libc_reent
335)
336{
337  _Thread_libc_reent = libc_reent;
338}
339
340/**@}*/
341
342#endif
343/* end of include file */
Note: See TracBrowser for help on using the repository browser.