RTEMS  5.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
threaddispatch.h
1 
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/isrlock.h>
19 #include <rtems/score/profiling.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24 
31 #if defined(RTEMS_SMP) || ( CPU_ENABLE_ROBUST_THREAD_DISPATCH == TRUE )
32 
40 #define RTEMS_SCORE_ROBUST_THREAD_DISPATCH
41 #endif
42 
52 {
53  bool enabled;
54 
55 #if defined(RTEMS_SMP)
56  ISR_Level level;
57 
58  _ISR_Local_disable( level );
59 #endif
60 
61  enabled = _Thread_Dispatch_disable_level == 0;
62 
63 #if defined(RTEMS_SMP)
64  _ISR_Local_enable( level );
65 #endif
66 
67  return enabled;
68 }
69 
76 {
77  return _Thread_Dispatch_disable_level;
78 }
79 
86 {
87  _Thread_Dispatch_disable_level = 1;
88 }
89 
107 void _Thread_Dispatch( void );
108 
121 void _Thread_Dispatch_direct( Per_CPU_Control *cpu_self );
122 
136 void _Thread_Do_dispatch( Per_CPU_Control *cpu_self, ISR_Level level );
137 
149  Per_CPU_Control *cpu_self,
150  const ISR_lock_Context *lock_context
151 )
152 {
153  uint32_t disable_level;
154 
155  disable_level = cpu_self->thread_dispatch_disable_level;
156  _Profiling_Thread_dispatch_disable_critical(
157  cpu_self,
158  disable_level,
159  lock_context
160  );
161  cpu_self->thread_dispatch_disable_level = disable_level + 1;
162 
163  return cpu_self;
164 }
165 
176  const ISR_lock_Context *lock_context
177 )
178 {
179  return _Thread_Dispatch_disable_with_CPU( _Per_CPU_Get(), lock_context );
180 }
181 
188 {
189  Per_CPU_Control *cpu_self;
190  ISR_lock_Context lock_context;
191 
192 #if defined( RTEMS_SMP ) || defined( RTEMS_PROFILING )
193  _ISR_lock_ISR_disable( &lock_context );
194 #endif
195 
196  cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
197 
198 #if defined( RTEMS_SMP ) || defined( RTEMS_PROFILING )
199  _ISR_lock_ISR_enable( &lock_context );
200 #endif
201 
202  return cpu_self;
203 }
204 
212 void _Thread_Dispatch_enable( Per_CPU_Control *cpu_self );
213 
220 {
221  _Assert( cpu_self->thread_dispatch_disable_level > 0 );
222  --cpu_self->thread_dispatch_disable_level;
223 }
224 
232  Per_CPU_Control *cpu_self,
233  Per_CPU_Control *cpu_target
234 )
235 {
236 #if defined( RTEMS_SMP )
237  if ( cpu_self == cpu_target ) {
238  cpu_self->dispatch_necessary = true;
239  } else {
240  _Atomic_Fetch_or_ulong( &cpu_target->message, 0, ATOMIC_ORDER_RELEASE );
241  _CPU_SMP_Send_interrupt( _Per_CPU_Get_index( cpu_target ) );
242  }
243 #else
244  cpu_self->dispatch_necessary = true;
245  (void) cpu_target;
246 #endif
247 }
248 
251 #ifdef __cplusplus
252 }
253 #endif /* __cplusplus */
254 
255 #endif /* _RTEMS_SCORE_THREADDISPATCH_H */
RTEMS_INLINE_ROUTINE uint32_t _Thread_Dispatch_get_disable_level(void)
Gets thread dispatch disable level.
Definition: threaddispatch.h:75
RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_is_enabled(void)
Indicates if the executing thread is inside a thread dispatch critical section.
Definition: threaddispatch.h:51
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
void _Thread_Dispatch(void)
Performs a thread dispatch if necessary.
Definition: threaddispatch.c:322
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable(void)
Disables thread dispatching.
Definition: threaddispatch.h:187
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:54
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:383
Profiling Support API.
uint32_t ISR_Level
Definition: isrlevel.h:38
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization(void)
Thread dispatch initialization.
Definition: threaddispatch.h:85
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:404
Per CPU Core Structure.
Definition: percpu.h:290
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:231
void _Thread_Dispatch_direct(Per_CPU_Control *cpu_self)
Directly do a thread dispatch.
Definition: threaddispatch.c:341
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:71
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:148
volatile bool dispatch_necessary
This is set to true when this processor needs to run the thread dispatcher.
Definition: percpu.h:343
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_unnest(Per_CPU_Control *cpu_self)
Unnests thread dispatching.
Definition: threaddispatch.h:219
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:328
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:175
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
void _Thread_Do_dispatch(Per_CPU_Control *cpu_self, ISR_Level level)
Performs a thread dispatch on the current processor.
Definition: threaddispatch.c:255
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
Definition: threaddispatch.c:353
ISR Locks.