source: rtems/cpukit/score/inline/rtems/score/thread.inl @ 4fc370e

4.115
Last change on this file since 4fc370e was 4fc370e, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 5, 2013 at 10:08:23 AM

score: Move thread dispatch content to new file

Move thread dispatch declarations and inline functions to new header
<rtems/score/threaddispatch.h> to make it independent of the
Thread_Control structure. This avoids a cyclic dependency in case
thread dispatch functions are used for the object implementation.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Inlined Routines from the Thread Handler
5 *
6 * This file contains the macro implementation of the inlined
7 * routines from the Thread handler.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2008.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
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/**
36 * This routine halts multitasking and returns control to
37 * the "thread" (i.e. the BSP) which initially invoked the
38 * routine which initialized the system.
39 */
40
41RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void )
42{
43#if defined(_CPU_Stop_multitasking)
44  _CPU_Stop_multitasking( &_Thread_BSP_context );
45#else
46  /*
47   *  This may look a bit of an odd but _Context_Restart_self is just
48   *  a very careful restore of a specific context which ensures that
49   *  if we were running within the same context, it would work.
50   *
51   *  And we will not return to this thread, so there is no point of
52   *  saving the context.
53   */
54  _Context_Restart_self( &_Thread_BSP_context );
55#endif
56
57  /***************************************************************
58   ***************************************************************
59   *   SYSTEM SHUTS DOWN!!!  WE DO NOT RETURN TO THIS POINT!!!   *
60   ***************************************************************
61   ***************************************************************
62   */
63}
64
65/**
66 * This function returns true if the_thread is the currently executing
67 * thread, and false otherwise.
68 */
69
70RTEMS_INLINE_ROUTINE bool _Thread_Is_executing (
71  const Thread_Control *the_thread
72)
73{
74  return ( the_thread == _Thread_Executing );
75}
76
77/**
78 * This function returns true if the_thread is the heir
79 * thread, and false otherwise.
80 */
81
82RTEMS_INLINE_ROUTINE bool _Thread_Is_heir (
83  const Thread_Control *the_thread
84)
85{
86  return ( the_thread == _Thread_Heir );
87}
88
89/**
90 * This function returns true if the currently executing thread
91 * is also the heir thread, and false otherwise.
92 */
93
94RTEMS_INLINE_ROUTINE bool _Thread_Is_executing_also_the_heir( void )
95{
96  return ( _Thread_Executing == _Thread_Heir );
97}
98
99/**
100 * This routine clears any blocking state for the_thread.  It performs
101 * any necessary scheduling operations including the selection of
102 * a new heir thread.
103 */
104
105RTEMS_INLINE_ROUTINE void _Thread_Unblock (
106  Thread_Control *the_thread
107)
108{
109  _Thread_Clear_state( the_thread, STATES_BLOCKED );
110}
111
112/**
113 * This routine resets the current context of the calling thread
114 * to that of its initial state.
115 */
116
117RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void )
118{
119#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
120  if ( _Thread_Executing->fp_context != NULL )
121    _Context_Restore_fp( &_Thread_Executing->fp_context );
122#endif
123
124  _CPU_Context_Restart_self( &_Thread_Executing->Registers );
125}
126
127/**
128 * This function returns true if the floating point context of
129 * the_thread is currently loaded in the floating point unit, and
130 * false otherwise.
131 */
132
133#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
134RTEMS_INLINE_ROUTINE bool _Thread_Is_allocated_fp (
135  const Thread_Control *the_thread
136)
137{
138  return ( the_thread == _Thread_Allocated_fp );
139}
140#endif
141
142/**
143 * This routine is invoked when the currently loaded floating
144 * point context is now longer associated with an active thread.
145 */
146
147#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
148RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void )
149{
150  _Thread_Allocated_fp = NULL;
151}
152#endif
153
154/**
155 * This function returns true if dispatching is disabled, and false
156 * otherwise.
157 */
158
159RTEMS_INLINE_ROUTINE bool _Thread_Is_context_switch_necessary( void )
160{
161  return ( _Thread_Dispatch_necessary );
162}
163
164/**
165 * This function returns true if the_thread is NULL and false otherwise.
166 */
167
168RTEMS_INLINE_ROUTINE bool _Thread_Is_null (
169  const Thread_Control *the_thread
170)
171{
172  return ( the_thread == NULL );
173}
174
175/**
176 * @brief Is proxy blocking.
177 *
178 * status which indicates that a proxy is blocking, and false otherwise.
179 */
180RTEMS_INLINE_ROUTINE bool _Thread_Is_proxy_blocking (
181  uint32_t   code
182)
183{
184  return (code == THREAD_STATUS_PROXY_BLOCKING);
185}
186
187/**
188 * This routine allocates an internal thread.
189 */
190
191RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
192{
193  return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
194}
195
196/**
197 * This routine frees an internal thread.
198 */
199
200RTEMS_INLINE_ROUTINE void _Thread_Internal_free (
201  Thread_Control *the_task
202)
203{
204  _Objects_Free( &_Thread_Internal_information, &the_task->Object );
205}
206
207RTEMS_INLINE_ROUTINE void _Thread_Set_global_exit_status(
208  uint32_t exit_status
209)
210{
211  Thread_Control *idle = (Thread_Control *)
212    _Thread_Internal_information.local_table[ 1 ];
213
214  idle->Wait.return_code = exit_status;
215}
216
217RTEMS_INLINE_ROUTINE uint32_t _Thread_Get_global_exit_status( void )
218{
219  const Thread_Control *idle = (const Thread_Control *)
220    _Thread_Internal_information.local_table[ 1 ];
221
222  return idle->Wait.return_code;
223}
224
225/**
226 * This routine returns the C library re-enterant pointer.
227 */
228
229RTEMS_INLINE_ROUTINE struct _reent **_Thread_Get_libc_reent( void )
230{
231  return _Thread_libc_reent;
232}
233
234/**
235 * This routine set the C library re-enterant pointer.
236 */
237
238RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent (
239  struct _reent **libc_reent
240)
241{
242  _Thread_libc_reent = libc_reent;
243}
244
245/**
246 * This routine evaluates the current scheduling information for the
247 * system and determines if a context switch is required.  This
248 * is usually called after changing an execution mode such as preemptability
249 * for a thread.
250 *
251 * @param[in] are_signals_pending specifies whether or not the API
252 *            level signals are pending and a dispatch is needed.
253 */
254RTEMS_INLINE_ROUTINE bool _Thread_Evaluate_is_dispatch_needed(
255  bool are_signals_pending
256)
257{
258  Thread_Control     *executing;
259
260  executing = _Thread_Executing;
261
262  if ( are_signals_pending ||
263       (!_Thread_Is_heir( executing ) && executing->is_preemptible) ) {
264    _Thread_Dispatch_necessary = true;
265    return true;
266  }
267
268  return false;
269}
270
271/** @}*/
272
273#endif
274/* end of include file */
Note: See TracBrowser for help on using the repository browser.