RTEMS 6.1-rc1
threaddispatch.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-2009.
14 * On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_SCORE_THREADDISPATCH_H
39#define _RTEMS_SCORE_THREADDISPATCH_H
40
41#include <rtems/score/percpu.h>
42#include <rtems/score/isrlock.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif /* __cplusplus */
48
55#if defined(RTEMS_SMP) || ( CPU_ENABLE_ROBUST_THREAD_DISPATCH == TRUE )
64#define RTEMS_SCORE_ROBUST_THREAD_DISPATCH
65#endif
66
75static inline bool _Thread_Dispatch_is_enabled(void)
76{
77 bool enabled;
78
79#if defined(RTEMS_SMP)
80 ISR_Level level;
81
82 _ISR_Local_disable( level );
83#endif
84
85 enabled = _Thread_Dispatch_disable_level == 0;
86
87#if defined(RTEMS_SMP)
88 _ISR_Local_enable( level );
89#endif
90
91 return enabled;
92}
93
99static inline uint32_t _Thread_Dispatch_get_disable_level(void)
100{
101 return _Thread_Dispatch_disable_level;
102}
103
109static inline void _Thread_Dispatch_initialization( void )
110{
111 _Thread_Dispatch_disable_level = 1;
112}
113
131void _Thread_Dispatch( void );
132
146
155 Per_CPU_Control *cpu_self
156);
157
171void _Thread_Do_dispatch( Per_CPU_Control *cpu_self, ISR_Level level );
172
183static inline Per_CPU_Control *_Thread_Dispatch_disable_with_CPU(
184 Per_CPU_Control *cpu_self,
185 const ISR_lock_Context *lock_context
186)
187{
188 uint32_t disable_level;
189
190 disable_level = cpu_self->thread_dispatch_disable_level;
191 _Profiling_Thread_dispatch_disable_critical(
192 cpu_self,
193 disable_level,
194 lock_context
195 );
196 cpu_self->thread_dispatch_disable_level = disable_level + 1;
197
198 return cpu_self;
199}
200
210static inline Per_CPU_Control *_Thread_Dispatch_disable_critical(
211 const ISR_lock_Context *lock_context
212)
213{
214 return _Thread_Dispatch_disable_with_CPU( _Per_CPU_Get(), lock_context );
215}
216
222static inline Per_CPU_Control *_Thread_Dispatch_disable( void )
223{
224 Per_CPU_Control *cpu_self;
225
226#if defined( RTEMS_SMP ) || defined( RTEMS_PROFILING )
227 ISR_lock_Context lock_context;
228
229 _ISR_lock_ISR_disable( &lock_context );
230
231 cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
232
233 _ISR_lock_ISR_enable( &lock_context );
234#else
235 cpu_self = _Thread_Dispatch_disable_critical( NULL );
236#endif
237
238 return cpu_self;
239}
240
249
255static inline void _Thread_Dispatch_unnest( Per_CPU_Control *cpu_self )
256{
257 _Assert( cpu_self->thread_dispatch_disable_level > 0 );
259}
260
267static inline void _Thread_Dispatch_request(
268 Per_CPU_Control *cpu_self,
269 Per_CPU_Control *cpu_target
270)
271{
272#if defined( RTEMS_SMP )
273 if ( cpu_self == cpu_target ) {
274 cpu_self->dispatch_necessary = true;
275 } else {
276 _Atomic_Fetch_or_ulong( &cpu_target->message, 0, ATOMIC_ORDER_RELEASE );
277 _CPU_SMP_Send_interrupt( _Per_CPU_Get_index( cpu_target ) );
278 }
279#else
280 cpu_self->dispatch_necessary = true;
281 (void) cpu_target;
282#endif
283}
284
287#ifdef __cplusplus
288}
289#endif /* __cplusplus */
290
291#endif /* _RTEMS_SCORE_THREADDISPATCH_H */
#define RTEMS_NO_RETURN
Tells the compiler in a function declaration that this function does not return.
Definition: basedefs.h:386
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:435
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:414
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:76
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:93
uint32_t ISR_Level
Definition: isrlevel.h:60
void _Thread_Dispatch(void)
Performs a thread dispatch if necessary.
Definition: threadplaindispatch.c:43
RTEMS_NO_RETURN void _Thread_Dispatch_direct_no_return(Per_CPU_Control *cpu_self)
Directly do a thread dispatch and do not return.
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
void _Thread_Dispatch_direct(Per_CPU_Control *cpu_self)
Directly do a thread dispatch.
Definition: threaddispatch.c:359
void _Thread_Do_dispatch(Per_CPU_Control *cpu_self, ISR_Level level)
Performs a thread dispatch on the current processor.
Definition: threaddispatch.c:277
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
This header file provides the interfaces of the ISR Locks.
This header file provides the interfaces of the Per-CPU Information.
This header file provides the interfaces of the Profiling Support.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:81
Per CPU Core Structure.
Definition: percpu.h:384
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:422
volatile bool dispatch_necessary
This is set to true when this processor needs to run the thread dispatcher.
Definition: percpu.h:437