RTEMS  5.1
threaddispatch.h
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2009.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifndef _RTEMS_SCORE_THREADDISPATCH_H
19 #define _RTEMS_SCORE_THREADDISPATCH_H
20 
21 #include <rtems/score/percpu.h>
22 #include <rtems/score/isrlock.h>
23 #include <rtems/score/profiling.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
35 #if defined(RTEMS_SMP) || ( CPU_ENABLE_ROBUST_THREAD_DISPATCH == TRUE )
36 
44 #define RTEMS_SCORE_ROBUST_THREAD_DISPATCH
45 #endif
46 
56 {
57  bool enabled;
58 
59 #if defined(RTEMS_SMP)
60  ISR_Level level;
61 
62  _ISR_Local_disable( level );
63 #endif
64 
65  enabled = _Thread_Dispatch_disable_level == 0;
66 
67 #if defined(RTEMS_SMP)
68  _ISR_Local_enable( level );
69 #endif
70 
71  return enabled;
72 }
73 
80 {
81  return _Thread_Dispatch_disable_level;
82 }
83 
90 {
91  _Thread_Dispatch_disable_level = 1;
92 }
93 
111 void _Thread_Dispatch( void );
112 
125 void _Thread_Dispatch_direct( Per_CPU_Control *cpu_self );
126 
140 void _Thread_Do_dispatch( Per_CPU_Control *cpu_self, ISR_Level level );
141 
153  Per_CPU_Control *cpu_self,
154  const ISR_lock_Context *lock_context
155 )
156 {
157  uint32_t disable_level;
158 
159  disable_level = cpu_self->thread_dispatch_disable_level;
160  _Profiling_Thread_dispatch_disable_critical(
161  cpu_self,
162  disable_level,
163  lock_context
164  );
165  cpu_self->thread_dispatch_disable_level = disable_level + 1;
166 
167  return cpu_self;
168 }
169 
180  const ISR_lock_Context *lock_context
181 )
182 {
183  return _Thread_Dispatch_disable_with_CPU( _Per_CPU_Get(), lock_context );
184 }
185 
192 {
193  Per_CPU_Control *cpu_self;
194  ISR_lock_Context lock_context;
195 
196 #if defined( RTEMS_SMP ) || defined( RTEMS_PROFILING )
197  _ISR_lock_ISR_disable( &lock_context );
198 #endif
199 
200  cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
201 
202 #if defined( RTEMS_SMP ) || defined( RTEMS_PROFILING )
203  _ISR_lock_ISR_enable( &lock_context );
204 #endif
205 
206  return cpu_self;
207 }
208 
216 void _Thread_Dispatch_enable( Per_CPU_Control *cpu_self );
217 
224 {
225  _Assert( cpu_self->thread_dispatch_disable_level > 0 );
226  --cpu_self->thread_dispatch_disable_level;
227 }
228 
236  Per_CPU_Control *cpu_self,
237  Per_CPU_Control *cpu_target
238 )
239 {
240 #if defined( RTEMS_SMP )
241  if ( cpu_self == cpu_target ) {
242  cpu_self->dispatch_necessary = true;
243  } else {
244  _Atomic_Fetch_or_ulong( &cpu_target->message, 0, ATOMIC_ORDER_RELEASE );
245  _CPU_SMP_Send_interrupt( _Per_CPU_Get_index( cpu_target ) );
246  }
247 #else
248  cpu_self->dispatch_necessary = true;
249  (void) cpu_target;
250 #endif
251 }
252 
255 #ifdef __cplusplus
256 }
257 #endif /* __cplusplus */
258 
259 #endif /* _RTEMS_SCORE_THREADDISPATCH_H */
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_request(Per_CPU_Control *cpu_self, Per_CPU_Control *cpu_target)
Requests a thread dispatch on the target processor.
Definition: threaddispatch.h:235
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_unnest(Per_CPU_Control *cpu_self)
Unnests thread dispatching.
Definition: threaddispatch.h:223
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable_critical(const ISR_lock_Context *lock_context)
Disables thread dispatching inside a critical section (interrupts disabled).
Definition: threaddispatch.h:179
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:57
void _Thread_Dispatch_direct(Per_CPU_Control *cpu_self)
Directly do a thread dispatch.
Definition: threaddispatch.c:350
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable_with_CPU(Per_CPU_Control *cpu_self, const ISR_lock_Context *lock_context)
Disables thread dispatching inside a critical section (interrupts disabled) with the current processo...
Definition: threaddispatch.h:152
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:419
void _Thread_Do_dispatch(Per_CPU_Control *cpu_self, ISR_Level level)
Performs a thread dispatch on the current processor.
Definition: threaddispatch.c:259
Profiling Support API.
Per CPU Core Structure.
Definition: percpu.h:347
uint32_t ISR_Level
Definition: isrlevel.h:41
RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_is_enabled(void)
Indicates if the executing thread is inside a thread dispatch critical section.
Definition: threaddispatch.h:55
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:74
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
Definition: threaddispatch.c:362
volatile bool dispatch_necessary
This is set to true when this processor needs to run the thread dispatcher.
Definition: percpu.h:400
RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_get_disable_level(void)
Gets thread dispatch disable level.
Definition: threaddispatch.h:79
void _Thread_Dispatch(void)
Performs a thread dispatch if necessary.
Definition: threaddispatch.c:331
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable(void)
Disables thread dispatching.
Definition: threaddispatch.h:191
volatile uint32_t thread_dispatch_disable_level
The thread dispatch critical section nesting counter which is used to prevent context switches at ino...
Definition: percpu.h:385
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization(void)
Thread dispatch initialization.
Definition: threaddispatch.h:89
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:398
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
ISR Locks.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100