source: rtems/cpukit/score/inline/rtems/score/thread.inl @ 23bbc43

4.115
Last change on this file since 23bbc43 was a55e305, checked in by Joel Sherrill <joel.sherrill@…>, on 07/29/10 at 17:52:10

2010-07-29 Gedare Bloom <giddyup44@…>

PR 1635/cpukit

  • sapi/src/exinit.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/bitfield.h, score/include/rtems/score/priority.h, score/include/rtems/score/thread.h, score/inline/rtems/score/priority.inl, score/inline/rtems/score/thread.inl, score/src/threadchangepriority.c, score/src/threadclearstate.c, score/src/threadready.c, score/src/threadresume.c, score/src/threadsetpriority.c, score/src/threadsetstate.c, score/src/threadsettransient.c, score/src/threadsuspend.c: Refactoring of priority handling, to isolate the bitmap implementation of priorities in the supercore so that priority management is a little more modular. This change is in anticipation of scheduler implementations that can select how they manage tracking priority levels / finding the highest priority ready task. Note that most of the changes here are simple renaming, to clarify the use of the bitmap-based priority management.
  • score/include/rtems/score/prioritybitmap.h, score/inline/rtems/score/prioritybitmap.inl: New files.
  • Property mode set to 100644
File size: 8.9 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  /*
43   *  This may look a bit of an odd but _Context_Restart_self is just
44   *  a very careful restore of a specific context which ensures that
45   *  if we were running within the same context, it would work.
46   *
47   *  And we will not return to this thread, so there is no point of
48   *  saving the context.
49   */
50  _Context_Restart_self( &_Thread_BSP_context );
51
52  /***************************************************************
53   ***************************************************************
54   *   SYSTEM SHUTS DOWN!!!  WE DO NOT RETURN TO THIS POINT!!!   *
55   ***************************************************************
56   ***************************************************************
57   */
58}
59
60/**
61 *  This function returns true if the_thread is the currently executing
62 *  thread, and false otherwise.
63 */
64
65RTEMS_INLINE_ROUTINE bool _Thread_Is_executing (
66  const Thread_Control *the_thread
67)
68{
69  return ( the_thread == _Thread_Executing );
70}
71
72/**
73 *  This function returns true if the_thread is the heir
74 *  thread, and false otherwise.
75 */
76
77RTEMS_INLINE_ROUTINE bool _Thread_Is_heir (
78  const Thread_Control *the_thread
79)
80{
81  return ( the_thread == _Thread_Heir );
82}
83
84/**
85 *  This function returns true if the currently executing thread
86 *  is also the heir thread, and false otherwise.
87 */
88
89RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_also_the_heir( void )
90{
91  return ( _Thread_Executing == _Thread_Heir );
92}
93
94/**
95 *  This routine clears any blocking state for the_thread.  It performs
96 *  any necessary scheduling operations including the selection of
97 *  a new heir thread.
98 */
99
100RTEMS_INLINE_ROUTINE void _Thread_Unblock (
101  Thread_Control *the_thread
102)
103{
104  _Thread_Clear_state( the_thread, STATES_BLOCKED );
105}
106
107/**
108 *  This routine resets the current context of the calling thread
109 *  to that of its initial state.
110 */
111
112RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void )
113{
114#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
115  if ( _Thread_Executing->fp_context != NULL )
116    _Context_Restore_fp( &_Thread_Executing->fp_context );
117#endif
118
119  _CPU_Context_Restart_self( &_Thread_Executing->Registers );
120}
121
122/**
123 *  This function returns a pointer to the highest priority
124 *  ready thread.
125 */
126
127RTEMS_INLINE_ROUTINE void _Thread_Calculate_heir( void )
128{
129  _Thread_Heir = (Thread_Control *)
130    _Thread_Ready_chain[ _Priority_bit_map_Get_highest() ].first;
131}
132
133/**
134 *  This function returns true if the floating point context of
135 *  the_thread is currently loaded in the floating point unit, and
136 *  false otherwise.
137 */
138
139#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
140RTEMS_INLINE_ROUTINE bool _Thread_Is_allocated_fp (
141  const Thread_Control *the_thread
142)
143{
144  return ( the_thread == _Thread_Allocated_fp );
145}
146#endif
147
148/**
149 *  This routine is invoked when the currently loaded floating
150 *  point context is now longer associated with an active thread.
151 */
152
153#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
154RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void )
155{
156  _Thread_Allocated_fp = NULL;
157}
158#endif
159
160/**
161 *  This routine prevents dispatching.
162 */
163
164#if defined(RTEMS_HEAVY_STACK_DEBUG) || defined(RTEMS_HEAVY_MALLOC_DEBUG)
165  #include <rtems/bspIo.h>
166  #include <rtems/fatal.h>
167  #include <rtems/stackchk.h>
168  #include <rtems/score/sysstate.h>
169  #include <rtems/score/heap.h>
170
171  /*
172   * This is currently not defined in any .h file, so we have to
173   * extern it here.
174   */
175  extern Heap_Control  *RTEMS_Malloc_Heap;
176#endif
177
178RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
179{
180  /*
181   *  This check is very brutal to system performance but is very helpful
182   *  at finding blown stack problems.  If you have a stack problem and
183   *  need help finding it, then uncomment this code.  Every system
184   *  call will check the stack and since mutexes are used frequently
185   *  in most systems, you might get lucky.
186   */
187  #if defined(RTEMS_HEAVY_STACK_DEBUG)
188    if (_System_state_Is_up(_System_state_Get()) && (_ISR_Nest_level == 0)) {
189      if ( rtems_stack_checker_is_blown() ) {
190        printk( "Stack blown!!\n" );
191        rtems_fatal_error_occurred( 99 );
192      }
193    }
194  #endif
195
196  _Thread_Dispatch_disable_level += 1;
197  RTEMS_COMPILER_MEMORY_BARRIER();
198
199  /*
200   * This check is even more brutal than the other one.  This enables
201   * malloc heap integrity checking upon entry to every system call.
202   */
203  #if defined(RTEMS_HEAVY_MALLOC_DEBUG)
204    if ( _Thread_Dispatch_disable_level == 1 ) {
205      _Heap_Walk( RTEMS_Malloc_Heap,99, false );
206    }
207  #endif
208}
209
210/**
211 *  This routine allows dispatching to occur again.  If this is
212 *  the outer most dispatching critical section, then a dispatching
213 *  operation will be performed and, if necessary, control of the
214 *  processor will be transferred to the heir thread.
215 */
216
217#if ( (defined(CPU_INLINE_ENABLE_DISPATCH) && \
218       (CPU_INLINE_ENABLE_DISPATCH == FALSE)) || \
219      (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1) )
220void _Thread_Enable_dispatch( void );
221#else
222/* inlining of enable dispatching must be true */
223RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch( void )
224{
225  RTEMS_COMPILER_MEMORY_BARRIER();
226  if ( (--_Thread_Dispatch_disable_level) == 0 )
227    _Thread_Dispatch();
228}
229#endif
230
231
232/**
233 *  This routine allows dispatching to occur again.  However,
234 *  no dispatching operation is performed even if this is the outer
235 *  most dispatching critical section.
236 */
237
238RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void )
239{
240  RTEMS_COMPILER_MEMORY_BARRIER();
241  _Thread_Dispatch_disable_level -= 1;
242}
243
244/**
245 *  This function returns true if dispatching is disabled, and false
246 *  otherwise.
247 */
248
249RTEMS_INLINE_ROUTINE bool _Thread_Is_dispatching_enabled( void )
250{
251  return ( _Thread_Dispatch_disable_level == 0 );
252}
253
254/**
255 *  This function returns true if dispatching is disabled, and false
256 *  otherwise.
257 */
258
259RTEMS_INLINE_ROUTINE bool _Thread_Is_context_switch_necessary( void )
260{
261  return ( _Context_Switch_necessary );
262}
263
264/**
265 *  This routine initializes the thread dispatching subsystem.
266 */
267
268RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
269{
270  _Thread_Dispatch_disable_level = 1;
271}
272
273/**
274 *  This function returns true if the_thread is NULL and false otherwise.
275 */
276
277RTEMS_INLINE_ROUTINE bool _Thread_Is_null (
278  const Thread_Control *the_thread
279)
280{
281  return ( the_thread == NULL );
282}
283
284/** @brief _Thread_Is_proxy_blocking
285 *
286 *  status which indicates that a proxy is blocking, and false otherwise.
287 */
288RTEMS_INLINE_ROUTINE bool _Thread_Is_proxy_blocking (
289  uint32_t   code
290)
291{
292  return (code == THREAD_STATUS_PROXY_BLOCKING);
293}
294
295/**
296 *  This routine allocates an internal thread.
297 */
298 
299RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
300{
301  return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
302}
303 
304/**
305 *  This routine frees an internal thread.
306 */
307 
308RTEMS_INLINE_ROUTINE void _Thread_Internal_free (
309  Thread_Control *the_task
310)
311{
312  _Objects_Free( &_Thread_Internal_information, &the_task->Object );
313}
314
315/**
316 *  This routine returns the C library re-enterant pointer.
317 */
318 
319RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void )
320{
321  return _Thread_libc_reent;
322}
323
324/**
325 *  This routine set the C library re-enterant pointer.
326 */
327 
328RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent (
329  struct _reent **libc_reent
330)
331{
332  _Thread_libc_reent = libc_reent;
333}
334
335/**
336 *  This routine evaluates the current scheduling information for the
337 *  system and determines if a context switch is required.  This
338 *  is usually called after changing an execution mode such as preemptability
339 *  for a thread.
340 *
341 *  @param[in] are_signals_pending specifies whether or not the API
342 *             level signals are pending and a dispatch is needed.
343 */
344RTEMS_INLINE_ROUTINE bool _Thread_Evaluate_is_dispatch_needed(
345  bool are_signals_pending
346)
347{
348  Thread_Control     *executing;
349
350  executing = _Thread_Executing;
351
352  if ( are_signals_pending ||
353       (!_Thread_Is_heir( executing ) && executing->is_preemptible) ) {
354    _Context_Switch_necessary = true;
355    return true;
356  }
357
358  return false;
359}
360
361/**@}*/
362
363#endif
364/* end of include file */
Note: See TracBrowser for help on using the repository browser.