source: rtems/cpukit/score/inline/rtems/score/thread.inl @ 760c817e

4.115
Last change on this file since 760c817e was d7c3883, checked in by Jennifer Averett <Jennifer.Averett@…>, on 04/21/11 at 19:05:15

2011-04-21 Jennifer Averett <Jennifer.Averett@…

PR 1777/cpukit

  • libcsupport/src/malloc_deferred.c, libcsupport/src/realloc.c, score/Makefile.am, score/cpu/lm32/irq.c, score/cpu/nios2/irq.c, score/include/rtems/score/coremutex.h, score/include/rtems/score/thread.h, score/inline/rtems/score/thread.inl, score/src/heapfree.c, score/src/pheapwalk.c, score/src/smp.c, score/src/threaddispatch.c: Consolidated access to _Thread_Dispatch_disable_level.
  • score/src/threaddisabledispatch.c, score/src/threadenabledispatch.c: New files.
  • Property mode set to 100644
File size: 8.5 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 returns true if thread dispatch indicates
36 * that we are in a critical section.
37 */
38RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_in_critical_section(void)
39{
40   if (  _Thread_Dispatch_disable_level == 0 )
41    return false;
42
43   return true;
44}
45
46/**
47 * This routine returns value of the the thread dispatch level.
48 */
49RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_get_disable_level(void)
50{
51  return _Thread_Dispatch_disable_level;
52}
53
54/**
55 * This routine sets thread dispatch level to the
56 * value passed in.
57 */
58RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_set_disable_level(uint32_t value)
59{
60  _Thread_Dispatch_disable_level = value;
61  return value;
62}
63
64/**
65 * This rountine increments the thread dispatch level
66 */
67RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_increment_disable_level(void)
68{
69  _Thread_Dispatch_disable_level++;
70  return _Thread_Dispatch_disable_level;
71}
72
73/**
74 * This routine decrements the thread dispatch level.
75 */
76RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_decrement_disable_level(void)
77{
78  _Thread_Dispatch_disable_level--;
79  return _Thread_Dispatch_disable_level;
80}
81
82/**
83 *  This routine initializes the thread dispatching subsystem.
84 */
85
86RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
87{
88  _Thread_Dispatch_set_disable_level( 1 );
89}
90
91
92/**
93 *  This routine halts multitasking and returns control to
94 *  the "thread" (i.e. the BSP) which initially invoked the
95 *  routine which initialized the system.
96 */
97
98RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void )
99{
100  /*
101   *  This may look a bit of an odd but _Context_Restart_self is just
102   *  a very careful restore of a specific context which ensures that
103   *  if we were running within the same context, it would work.
104   *
105   *  And we will not return to this thread, so there is no point of
106   *  saving the context.
107   */
108  _Context_Restart_self( &_Thread_BSP_context );
109
110  /***************************************************************
111   ***************************************************************
112   *   SYSTEM SHUTS DOWN!!!  WE DO NOT RETURN TO THIS POINT!!!   *
113   ***************************************************************
114   ***************************************************************
115   */
116}
117
118/**
119 *  This function returns true if the_thread is the currently executing
120 *  thread, and false otherwise.
121 */
122
123RTEMS_INLINE_ROUTINE bool _Thread_Is_executing (
124  const Thread_Control *the_thread
125)
126{
127  return ( the_thread == _Thread_Executing );
128}
129
130/**
131 *  This function returns true if the_thread is the heir
132 *  thread, and false otherwise.
133 */
134
135RTEMS_INLINE_ROUTINE bool _Thread_Is_heir (
136  const Thread_Control *the_thread
137)
138{
139  return ( the_thread == _Thread_Heir );
140}
141
142/**
143 *  This function returns true if the currently executing thread
144 *  is also the heir thread, and false otherwise.
145 */
146
147RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_also_the_heir( void )
148{
149  return ( _Thread_Executing == _Thread_Heir );
150}
151
152/**
153 *  This routine clears any blocking state for the_thread.  It performs
154 *  any necessary scheduling operations including the selection of
155 *  a new heir thread.
156 */
157
158RTEMS_INLINE_ROUTINE void _Thread_Unblock (
159  Thread_Control *the_thread
160)
161{
162  _Thread_Clear_state( the_thread, STATES_BLOCKED );
163}
164
165/**
166 *  This routine resets the current context of the calling thread
167 *  to that of its initial state.
168 */
169
170RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void )
171{
172#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
173  if ( _Thread_Executing->fp_context != NULL )
174    _Context_Restore_fp( &_Thread_Executing->fp_context );
175#endif
176
177  _CPU_Context_Restart_self( &_Thread_Executing->Registers );
178}
179
180/**
181 *  This function returns true if the floating point context of
182 *  the_thread is currently loaded in the floating point unit, and
183 *  false otherwise.
184 */
185
186#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
187RTEMS_INLINE_ROUTINE bool _Thread_Is_allocated_fp (
188  const Thread_Control *the_thread
189)
190{
191  return ( the_thread == _Thread_Allocated_fp );
192}
193#endif
194
195/**
196 *  This routine is invoked when the currently loaded floating
197 *  point context is now longer associated with an active thread.
198 */
199
200#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
201RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void )
202{
203  _Thread_Allocated_fp = NULL;
204}
205#endif
206
207/**
208 *  This routine prevents dispatching.
209 */
210
211#if defined ( __THREAD_DO_NOT_INLINE_DISABLE_DISPATCH__ )
212void _Thread_Disable_dispatch( void );
213#else
214RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
215{
216  _Thread_Dispatch_increment_disable_level();
217  RTEMS_COMPILER_MEMORY_BARRIER();
218}
219#endif
220
221/**
222 *  This routine allows dispatching to occur again.  If this is
223 *  the outer most dispatching critical section, then a dispatching
224 *  operation will be performed and, if necessary, control of the
225 *  processor will be transferred to the heir thread.
226 */
227
228#if defined ( __THREAD_DO_NOT_INLINE_ENABLE_DISPATCH__ )
229  void _Thread_Enable_dispatch( void );
230#else
231  /* inlining of enable dispatching must be true */
232  RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch( void )
233  {
234    RTEMS_COMPILER_MEMORY_BARRIER();
235    if ( _Thread_Dispatch_decrement_disable_level() == 0 )
236      _Thread_Dispatch();
237  }
238#endif
239
240/**
241 *  This routine allows dispatching to occur again.  However,
242 *  no dispatching operation is performed even if this is the outer
243 *  most dispatching critical section.
244 */
245
246RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void )
247{
248  RTEMS_COMPILER_MEMORY_BARRIER();
249  _Thread_Dispatch_decrement_disable_level();
250}
251
252/**
253 *  This function returns true if dispatching is disabled, and false
254 *  otherwise.
255 */
256
257RTEMS_INLINE_ROUTINE bool _Thread_Is_dispatching_enabled( void )
258{
259  return  ( _Thread_Dispatch_in_critical_section() == false );
260}
261
262/**
263 *  This function returns true if dispatching is disabled, and false
264 *  otherwise.
265 */
266
267RTEMS_INLINE_ROUTINE bool _Thread_Is_context_switch_necessary( void )
268{
269  return ( _Thread_Dispatch_necessary );
270}
271
272/**
273 *  This function returns true if the_thread is NULL and false otherwise.
274 */
275
276RTEMS_INLINE_ROUTINE bool _Thread_Is_null (
277  const Thread_Control *the_thread
278)
279{
280  return ( the_thread == NULL );
281}
282
283/** @brief _Thread_Is_proxy_blocking
284 *
285 *  status which indicates that a proxy is blocking, and false otherwise.
286 */
287RTEMS_INLINE_ROUTINE bool _Thread_Is_proxy_blocking (
288  uint32_t   code
289)
290{
291  return (code == THREAD_STATUS_PROXY_BLOCKING);
292}
293
294/**
295 *  This routine allocates an internal thread.
296 */
297 
298RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
299{
300  return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
301}
302 
303/**
304 *  This routine frees an internal thread.
305 */
306 
307RTEMS_INLINE_ROUTINE void _Thread_Internal_free (
308  Thread_Control *the_task
309)
310{
311  _Objects_Free( &_Thread_Internal_information, &the_task->Object );
312}
313
314/**
315 *  This routine returns the C library re-enterant pointer.
316 */
317 
318RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void )
319{
320  return _Thread_libc_reent;
321}
322
323/**
324 *  This routine set the C library re-enterant pointer.
325 */
326 
327RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent (
328  struct _reent **libc_reent
329)
330{
331  _Thread_libc_reent = libc_reent;
332}
333
334/**
335 *  This routine evaluates the current scheduling information for the
336 *  system and determines if a context switch is required.  This
337 *  is usually called after changing an execution mode such as preemptability
338 *  for a thread.
339 *
340 *  @param[in] are_signals_pending specifies whether or not the API
341 *             level signals are pending and a dispatch is needed.
342 */
343RTEMS_INLINE_ROUTINE bool _Thread_Evaluate_is_dispatch_needed(
344  bool are_signals_pending
345)
346{
347  Thread_Control     *executing;
348
349  executing = _Thread_Executing;
350
351  if ( are_signals_pending ||
352       (!_Thread_Is_heir( executing ) && executing->is_preemptible) ) {
353    _Thread_Dispatch_necessary = true;
354    return true;
355  }
356
357  return false;
358}
359
360/**@}*/
361
362#endif
363/* end of include file */
Note: See TracBrowser for help on using the repository browser.