µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::rtos::scheduler Namespace Reference

Scheduler namespace. More...

Namespaces

namespace  statistics
 Scheduler statistics.
 

Classes

class  critical_section
 Scheduler critical section RAII helper. More...
 
class  lockable
 Scheduler standard locker. More...
 
class  uncritical_section
 Scheduler uncritical section RAII helper. More...
 

Typedefs

using state_t = port::scheduler::state_t
 Type of variables holding scheduler state codes.
 

Functions

thread::threads_list & children_threads (thread *th)
 Get the children threads.
 
result_t initialize (void)
 Initialise the RTOS scheduler.
 
state_t lock (void)
 Lock the scheduler.
 
state_t locked (state_t state)
 Lock/unlock the scheduler.
 
bool locked (void)
 Check if the scheduler is locked.
 
bool preemptive (bool state)
 Set the scheduler preemptive mode.
 
bool preemptive (void)
 Check if the scheduler is in preemptive mode.
 
void start (void)
 Start the RTOS scheduler.
 
bool started (void)
 Check if the scheduler was started.
 
state_t unlock (void)
 Unlock the scheduler.
 

Detailed Description

The os::rtos::scheduler namespace groups scheduler types and functions.

Typedef Documentation

◆ state_t

using os::rtos::scheduler::state_t = typedef port::scheduler::state_t

Usually a boolean telling if the scheduler is locked or not, but for recursive locks it might also be a numeric counter.

Definition at line 200 of file os-decls.h.

Function Documentation

◆ children_threads()

thread::threads_list & os::rtos::scheduler::children_threads ( thread th)
Parameters
[in]thPointer to thread or nullptr.
Returns
Reference to children list.

If the input pointer is nullptr, the function returns the list of top level threads.

Definition at line 265 of file os-core.cpp.

266 {
267 if (th == nullptr)
268 {
269 return top_threads_list_;
270 }
271 else
272 {
273 return th->children_;
274 }
275 }

Referenced by os_children_threads_iter_begin(), and os_children_threads_iter_end().

◆ initialize()

result_t os::rtos::scheduler::initialize ( void  )
Parameters
None.
Return values
result::okThe scheduler was initialised.
EPERMCannot be invoked from an Interrupt Service Routines.

Initialise all RTOS internal objects and be ready to run.

Must be called only once, usually in main().

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 164 of file os-core.cpp.

165 {
166#if defined(OS_TRACE_RTOS_SCHEDULER)
167 trace::printf ("scheduler::%s() \n", __func__);
168#endif
169
170 // Don't call this from interrupt handlers.
171 os_assert_err (!interrupts::in_handler_mode (), EPERM);
172
173#if defined(OS_USE_RTOS_PORT_SCHEDULER)
174
175 return port::scheduler::initialize ();
176
177#else
178
179 port::scheduler::initialize ();
180
181 return result::ok;
182#endif
183 }
#define os_assert_err(__e, __er)
Assert or return an error.
Definition os-decls.h:1101

References os::rtos::interrupts::in_handler_mode(), os::rtos::port::scheduler::initialize(), os::rtos::result::ok, os_assert_err, and os::trace::printf().

Referenced by os_sched_initialize(), and osKernelInitialize().

◆ lock()

state_t os::rtos::scheduler::lock ( void  )
inline
Parameters
None.
Returns
The previous state of the scheduler lock.

Set the scheduler lock state to locked and return the previous state.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 871 of file os-sched.h.

872 {
873 return port::scheduler::lock ();
874 }

References os::rtos::port::scheduler::lock().

Referenced by os::rtos::scheduler::lockable::lock(), os_sched_lock(), and os::rtos::scheduler::lockable::try_lock().

◆ locked() [1/2]

state_t os::rtos::scheduler::locked ( state_t  state)
inline
Parameters
[in]stateThe new state of the scheduler lock.
Returns
The previous state of the scheduler lock.

Set the scheduler lock state based on the parameter and return the previous state.

This allows to implement scheduler critical sections, where the scheduler is disabled and context switches are not performed.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 901 of file os-sched.h.

902 {
903 return port::scheduler::locked (state);
904 }

References os::rtos::port::scheduler::locked().

◆ locked() [2/2]

◆ preemptive() [1/2]

bool os::rtos::scheduler::preemptive ( bool  state)
Parameters
[in]stateThe new state of the scheduler preemptive mode.
Returns
The previous state of the preemptive mode.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 231 of file os-core.cpp.

232 {
233#if defined(OS_TRACE_RTOS_SCHEDULER)
234 trace::printf ("scheduler::%s(%d) \n", __func__, state);
235#endif
236 // Don't call this from interrupt handlers.
237 os_assert_throw (!interrupts::in_handler_mode (), EPERM);
238
239#if defined(OS_USE_RTOS_PORT_SCHEDULER)
240
241 return port::scheduler::preemptive (state);
242
243#else
244 bool tmp;
245
246 {
247 // ----- Enter critical section -------------------------------------
249
250 tmp = is_preemptive_;
251 is_preemptive_ = state;
252 // ----- Exit critical section --------------------------------------
253 }
254
255 return tmp;
256#endif
257 }
Interrupts critical section RAII helper.
Definition os-sched.h:502
#define os_assert_throw(__e, __er)
Assert or throw a system error exception.
Definition os-decls.h:1122

References os::rtos::interrupts::in_handler_mode(), os_assert_throw, os::rtos::port::scheduler::preemptive(), and os::trace::printf().

◆ preemptive() [2/2]

bool os::rtos::scheduler::preemptive ( void  )
inline
Parameters
None
Return values
trueThe scheduler is in preemptive mode.
falseThe scheduler is not in preemptive mode.

Check if the scheduler preemption is enabled.

Note
Can be invoked from Interrupt Service Routines.

Definition at line 841 of file os-sched.h.

842 {
843#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
844 return is_preemptive_;
845#else
846 return port::scheduler::preemptive ();
847#endif
848 }

References os::rtos::port::scheduler::preemptive().

Referenced by os_sched_is_preemptive(), and os_sched_set_preemptive().

◆ start()

void os::rtos::scheduler::start ( void  )
Parameters
None.
Returns
Nothing.

The scheduler cannot be stopped, it will run forever, but thread switching can be locked/unlocked.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 193 of file os-core.cpp.

194 {
195 trace::printf ("scheduler::%s() \n", __func__);
196
197 // Don't call this from interrupt handlers.
198 os_assert_throw (!interrupts::in_handler_mode (), EPERM);
199
200 sysclock.start ();
201 hrclock.start ();
202
203 rtclock.start ();
204
205#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
206
207 scheduler::statistics::context_switches_ = 0;
208
209#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
210
211#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
212
213 scheduler::statistics::cpu_cycles_ = 0;
214 scheduler::statistics::switch_timestamp_ = hrclock.now ();
215
216#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
217
218#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
219 is_preemptive_ = OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE;
220#endif /* defined(OS_USE_RTOS_PORT_SCHEDULER) */
221
222 is_started_ = true;
223
224 port::scheduler::start ();
225 }
virtual void start(void) override
Start the clock.
virtual timestamp_t now(void) override
Tell the current time.
virtual void start(void) override
Initialise and make the RTC tick.
virtual void start(void) override
Start the clock.
#define OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE
Default definition for the pre-emption flag.
clock_highres hrclock
The high resolution clock object instance.
clock_rtc rtclock
The real time clock object instance.
clock_systick sysclock
The system clock object instance.

References os::rtos::hrclock, os::rtos::interrupts::in_handler_mode(), os::rtos::clock_highres::now(), os_assert_throw, OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE, os::trace::printf(), os::rtos::rtclock, os::rtos::port::scheduler::start(), os::rtos::clock_systick::start(), os::rtos::clock_rtc::start(), os::rtos::clock_highres::start(), and os::rtos::sysclock.

Referenced by os_sched_start(), and osKernelStart().

◆ started()

bool os::rtos::scheduler::started ( void  )
inline
Parameters
None.
Return values
trueThe scheduler was started.
falseThe scheduler was not started.

Check if the scheduler was started, i.e. if scheduler::start() was called.

Note
Can be invoked from Interrupt Service Routines.

Definition at line 829 of file os-sched.h.

830 {
831 return is_started_;
832 }

Referenced by os_rtc_handler(), os_sched_is_started(), os_systick_handler(), osKernelRunning(), and os::rtos::this_thread::yield().

◆ unlock()

state_t os::rtos::scheduler::unlock ( void  )
inline
Parameters
None.
Returns
The previous state of the scheduler lock.

Set the scheduler lock state to unlocked and return the previous state.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 884 of file os-sched.h.

885 {
886 return port::scheduler::unlock ();
887 }

References os::rtos::port::scheduler::unlock().

Referenced by os_sched_unlock().