source: rtems/cpukit/score/include/rtems/score/threaddispatch.h @ 89f8eab5

4.115
Last change on this file since 89f8eab5 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/**
2 * @brief Constants and Structures Related with Thread Dispatch
3 */
4
5/*
6 * COPYRIGHT (c) 1989-2009.
7 * On-Line Applications Research Corporation (OAR).
8 *
9 * The license and distribution terms for this file may be
10 * found in the file LICENSE in this distribution or at
11 * http://www.rtems.org/license/LICENSE.
12 */
13
14#ifndef _RTEMS_SCORE_THREADDISPATCH_H
15#define _RTEMS_SCORE_THREADDISPATCH_H
16
17#include <rtems/score/percpu.h>
18#include <rtems/score/smplock.h>
19#include <rtems/score/profiling.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif /* __cplusplus */
24
25#if defined(RTEMS_SMP) || \
26    defined(RTEMS_HEAVY_STACK_DEBUG) || \
27    defined(RTEMS_HEAVY_MALLOC_DEBUG)
28  #define __THREAD_DO_NOT_INLINE_DISABLE_DISPATCH__
29#endif
30
31#if defined(RTEMS_SMP) || \
32   (CPU_INLINE_ENABLE_DISPATCH == FALSE) || \
33   (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1)
34  #define __THREAD_DO_NOT_INLINE_ENABLE_DISPATCH__
35#endif
36
37/**
38 * @addtogroup ScoreThread
39 *
40 * @{
41 */
42
43/**
44 * @brief Indicates if the executing thread is inside a thread dispatch
45 * critical section.
46 *
47 * @retval true Thread dispatching is enabled.
48 * @retval false The executing thread is inside a thread dispatch critical
49 * section and dispatching is not allowed.
50 */
51RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_is_enabled(void)
52{
53  bool enabled;
54
55#if defined(RTEMS_SMP)
56  ISR_Level level;
57
58  _ISR_Disable_without_giant( level );
59#endif
60
61  enabled = _Thread_Dispatch_disable_level == 0;
62
63#if defined(RTEMS_SMP)
64  _ISR_Enable_without_giant( level );
65#endif
66
67  return enabled;
68}
69
70/**
71 * @briefs Gets thread dispatch disable level.
72 *
73 * @return The value of the thread dispatch level.
74 */
75RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_get_disable_level(void)
76{
77  return _Thread_Dispatch_disable_level;
78}
79
80/**
81 * @brief Thread dispatch initialization.
82 *
83 * This routine initializes the thread dispatching subsystem.
84 */
85RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
86{
87  _Thread_Dispatch_disable_level = 1;
88}
89
90#if defined(RTEMS_SMP)
91  /**
92   * @brief Acquires the giant lock.
93   *
94   * The giant lock is a recursive SMP lock protecting nearly all operating
95   * system services.
96   *
97   * This lock is implicitly acquired in
98   * _Thread_Dispatch_increment_disable_level().
99   *
100   * Thread dispatching must be disabled before this lock can be acquired.
101   */
102  void _Giant_Acquire( void );
103
104  /**
105   * @brief Releases the giant lock.
106   *
107   * This lock is implicitly released in
108   * _Thread_Dispatch_decrement_disable_level().
109   */
110  void _Giant_Release( void );
111
112  /**
113   * @brief Releases the giant lock completely if held by the executing processor.
114   *
115   * The thread dispatch disable level is not altered by this function.
116   *
117   * The only use case for this operation is in _SMP_Request_shutdown().
118   *
119   * @param[in] self_cpu The current processor.
120   */
121  void _Giant_Drop( Per_CPU_Control *self_cpu );
122
123  /**
124   *  @brief Increments the thread dispatch level.
125   *
126   * This rountine increments the thread dispatch level
127   */
128  uint32_t _Thread_Dispatch_increment_disable_level(void);
129
130  /**
131   *  @brief Decrements the thread dispatch level.
132   *
133   * This routine decrements the thread dispatch level.
134   */
135  uint32_t _Thread_Dispatch_decrement_disable_level(void);
136#else /* RTEMS_SMP */
137  /**
138   * @brief Increase thread dispatch disable level.
139   *
140   * This rountine increments the thread dispatch level
141   */
142  RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_increment_disable_level(void)
143  {
144    uint32_t disable_level = _Thread_Dispatch_disable_level;
145#if defined( RTEMS_PROFILING )
146    ISR_Level level;
147
148    _ISR_Disable( level );
149    _Profiling_Thread_dispatch_disable( _Per_CPU_Get(), disable_level );
150#endif
151
152    ++disable_level;
153    _Thread_Dispatch_disable_level = disable_level;
154
155#if defined( RTEMS_PROFILING )
156    _ISR_Enable( level );
157#endif
158
159    return disable_level;
160  }
161
162  /**
163   * @brief Decrease thread dispatch disable level.
164   *
165   * This routine decrements the thread dispatch level.
166   */
167  RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_decrement_disable_level(void)
168  {
169    uint32_t disable_level = _Thread_Dispatch_disable_level;
170#if defined( RTEMS_PROFILING )
171    ISR_Level level;
172
173    _ISR_Disable( level );
174#endif
175
176    --disable_level;
177    _Thread_Dispatch_disable_level = disable_level;
178
179#if defined( RTEMS_PROFILING )
180    _Profiling_Thread_dispatch_enable( _Per_CPU_Get(), disable_level );
181    _ISR_Enable( level );
182#endif
183
184    return disable_level;
185  }
186#endif /* RTEMS_SMP */
187
188/**
189 *  @brief Dispatch thread.
190 *
191 *  This routine is responsible for transferring control of the
192 *  processor from the executing thread to the heir thread. Once the
193 *  heir is running an attempt is made to dispatch any ASRs.
194 *  As part of this process, it is responsible for the following actions:
195 *     + saving the context of the executing thread
196 *     + restoring the context of the heir thread
197 *     + dispatching any signals for the resulting executing thread
198
199 *  ALTERNATE ENTRY POINTS:
200 *    void _Thread_Enable_dispatch();
201 *
202 *  - INTERRUPT LATENCY:
203 *    + dispatch thread
204 *    + no dispatch thread
205 */
206void _Thread_Dispatch( void );
207
208/**
209 * This routine prevents dispatching.
210 */
211
212#if defined ( __THREAD_DO_NOT_INLINE_DISABLE_DISPATCH__ )
213void _Thread_Disable_dispatch( void );
214#else
215RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
216{
217  _Thread_Dispatch_increment_disable_level();
218  RTEMS_COMPILER_MEMORY_BARRIER();
219}
220#endif
221
222/**
223 * This routine allows dispatching to occur again.  If this is
224 * the outer most dispatching critical section, then a dispatching
225 * operation will be performed and, if necessary, control of the
226 * processor will be transferred to the heir thread.
227 */
228
229#if defined ( __THREAD_DO_NOT_INLINE_ENABLE_DISPATCH__ )
230  void _Thread_Enable_dispatch( void );
231#else
232  /* inlining of enable dispatching must be true */
233  RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch( void )
234  {
235    RTEMS_COMPILER_MEMORY_BARRIER();
236    if ( _Thread_Dispatch_decrement_disable_level() == 0 )
237      _Thread_Dispatch();
238  }
239#endif
240
241/**
242 * This routine allows dispatching to occur again.  However,
243 * no dispatching operation is performed even if this is the outer
244 * most dispatching critical section.
245 */
246
247RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void )
248{
249  RTEMS_COMPILER_MEMORY_BARRIER();
250  _Thread_Dispatch_decrement_disable_level();
251}
252
253/** @} */
254
255#ifdef __cplusplus
256}
257#endif /* __cplusplus */
258
259#endif /* _RTEMS_SCORE_THREADDISPATCH_H */
Note: See TracBrowser for help on using the repository browser.