RTEMS 6.1-rc2
Loading...
Searching...
No Matches
scheduleruniimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2010 Gedare Bloom.
14 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
15 * Copyright (C) 2014, 2022 embedded brains GmbH & Co. KG
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef _RTEMS_SCORE_SCHEDULERUNIIMPL_H
40#define _RTEMS_SCORE_SCHEDULERUNIIMPL_H
41
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
60static inline void _Scheduler_uniprocessor_Update_heir(
61 Thread_Control *heir,
62 Thread_Control *new_heir
63)
64{
65 _Assert( heir != new_heir );
66#if defined(RTEMS_SMP)
67 /*
68 * We need this state only for _Thread_Get_CPU_time_used_locked(). Cannot
69 * use _Scheduler_Thread_change_state() since THREAD_SCHEDULER_BLOCKED to
70 * THREAD_SCHEDULER_BLOCKED state changes are illegal for the real SMP
71 * schedulers.
72 */
73 heir->Scheduler.state = THREAD_SCHEDULER_BLOCKED;
74 new_heir->Scheduler.state = THREAD_SCHEDULER_SCHEDULED;
75#endif
76 _Thread_Update_CPU_time_used( heir, _Thread_Get_CPU( heir ) );
77 _Thread_Heir = new_heir;
78 _Thread_Dispatch_necessary = true;
79}
80
89static inline void _Scheduler_uniprocessor_Update_heir_if_necessary(
90 Thread_Control *new_heir
91)
92{
93 Thread_Control *heir = _Thread_Heir;
94
95 if ( heir != new_heir ) {
96 _Scheduler_uniprocessor_Update_heir( heir, new_heir );
97 }
98}
99
107static inline void _Scheduler_uniprocessor_Update_heir_if_preemptible(
108 Thread_Control *heir,
109 Thread_Control *new_heir
110)
111{
112 if ( heir != new_heir && heir->is_preemptible ) {
113 _Scheduler_uniprocessor_Update_heir( heir, new_heir );
114 }
115}
116
126static inline void _Scheduler_uniprocessor_Block(
127 const Scheduler_Control *scheduler,
128 Thread_Control *the_thread,
129 Scheduler_Node *node,
130 void ( *extract )(
131 const Scheduler_Control *,
134 ),
135 Thread_Control *( *get_highest_ready )( const Scheduler_Control * )
136)
137{
138 ( *extract )( scheduler, the_thread, node );
139
140 /* TODO: flash critical section? */
141
142 if ( _Thread_Is_heir( the_thread ) ) {
143 Thread_Control *highest_ready;
144
145 highest_ready = ( *get_highest_ready )( scheduler );
146 _Scheduler_uniprocessor_Update_heir( _Thread_Heir, highest_ready );
147 }
148}
149
157static inline void _Scheduler_uniprocessor_Unblock(
158 const Scheduler_Control *scheduler,
159 Thread_Control *the_thread,
160 Priority_Control priority
161)
162{
163 Thread_Control *heir;
164
165 heir = _Thread_Heir;
166
167 /*
168 * If the thread is more important than the heir, then we have a new heir.
169 * This may or may not result in a context switch. If the current heir
170 * thread is preemptible, then we need to do a context switch.
171 */
172 if ( priority < _Thread_Get_priority( heir ) ) {
173 _Scheduler_uniprocessor_Update_heir_if_preemptible( heir, the_thread );
174 }
175}
176
184static inline void _Scheduler_uniprocessor_Schedule(
185 const Scheduler_Control *scheduler,
186 Thread_Control *( *get_highest_ready )( const Scheduler_Control * )
187)
188{
189 Thread_Control *highest_ready;
190
191 highest_ready = ( *get_highest_ready )( scheduler );
192 _Scheduler_uniprocessor_Update_heir_if_preemptible(
193 _Thread_Heir,
194 highest_ready
195 );
196}
197
204static inline void _Scheduler_uniprocessor_Yield(
205 const Scheduler_Control *scheduler,
206 Thread_Control *( *get_highest_ready )( const Scheduler_Control * )
207)
208{
209 Thread_Control *highest_ready;
210
211 highest_ready = ( *get_highest_ready )( scheduler );
212 _Scheduler_uniprocessor_Update_heir_if_necessary( highest_ready );
213}
214
217#ifdef __cplusplus
218}
219#endif
220
221#endif /* _RTEMS_SCORE_SCHEDULERUNIIMPL_H */
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:91
This header file provides interfaces of the Scheduler Handler which are only used by the implementati...
Scheduler node for per-thread data.
Definition: schedulernode.h:94
Scheduler control.
Definition: scheduler.h:335
Definition: thread.h:812
Thread_Scheduler_control Scheduler
Scheduler related control.
Definition: thread.h:849
bool is_preemptible
Definition: thread.h:889