µ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::critical_section Class Reference

Scheduler critical section RAII helper. More...

#include <cmsis-plus/rtos/os.h>

Public Member Functions

Constructors & Destructor
 critical_section ()
 Enter a critical section.
 
 ~critical_section ()
 Exit a critical section.
 

Detailed Description

Use this class to define a critical section protected to scheduler switches. The beginning of the critical section is exactly the place where this class is instantiated (the constructor will lock the scheduler). The end of the critical section is the end of the surrounding block (the destructor will unlock the scheduler).

Note
Can be nested as many times as required without problems, only the outer call will unlock the scheduler.
Example
void
func(void)
{
// Do something
{
scheduler::critical_section scs; // Critical section begins
here.
// Inside the critical section.
// No scheduler switches will happen here.
} // Critical section ends here.
// Do something else.
}
Scheduler critical section RAII helper.
Definition os-sched.h:171

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

Constructor & Destructor Documentation

◆ critical_section()

os::rtos::scheduler::critical_section::critical_section ( )
inline
Parameters
None.

Lock the scheduler and remember the initial scheduler state.

Warning
Cannot be invoked from Interrupt Service Routines.

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

912 : state_ (lock ())
913 {
914#if defined(OS_TRACE_RTOS_SCHEDULER)
915 trace::printf ("{C ");
916#endif
917 }
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
state_t lock(void)
Lock the scheduler.
Definition os-sched.h:871

References os::trace::printf().

◆ ~critical_section()

os::rtos::scheduler::critical_section::~critical_section ( )
inline

Restore the initial scheduler state and possibly unlock the scheduler.

Warning
Cannot be invoked from Interrupt Service Routines.

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

927 {
928#if defined(OS_TRACE_RTOS_SCHEDULER)
929 trace::printf (" C}");
930#endif
931 locked (state_);
932 }
bool locked(void)
Check if the scheduler is locked.
Definition os-sched.h:858

References os::rtos::scheduler::locked(), and os::trace::printf().


The documentation for this class was generated from the following file: