mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5621 from maciejbocianski/critical_section_imp2
CriticalSectionLock class improvementpull/5746/merge
commit
eda0acc5da
|
@ -33,14 +33,25 @@ namespace mbed {
|
||||||
* Usage:
|
* Usage:
|
||||||
* @code
|
* @code
|
||||||
*
|
*
|
||||||
* void f() {
|
* // RAII style usage
|
||||||
* // some code here
|
* unsigned int atomic_counter_increment(unsigned int &counter) {
|
||||||
* {
|
* CriticalSectionLock lock;
|
||||||
* CriticalSectionLock lock;
|
* // Code in this block will run with interrupts disabled
|
||||||
* // Code in this block will run with interrupts disabled
|
* // Interrupts will be restored to their previous state automatically
|
||||||
* }
|
* // at the end of function scope
|
||||||
* // interrupts will be restored to their previous state
|
* return ++counter;
|
||||||
* }
|
* }
|
||||||
|
*
|
||||||
|
* // free locking usage
|
||||||
|
* unsigned int atomic_counter_decrement(unsigned int &counter) {
|
||||||
|
* CriticalSectionLock::enable();
|
||||||
|
* // Code in this block will run with interrupts disabled
|
||||||
|
* counter--;
|
||||||
|
* CriticalSectionLock::disable(); // need explicitly to disable critical section lock
|
||||||
|
* // interrupts will be restored to their previous state here
|
||||||
|
* return counter;
|
||||||
|
* }
|
||||||
|
*
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
class CriticalSectionLock {
|
class CriticalSectionLock {
|
||||||
|
@ -58,6 +69,9 @@ public:
|
||||||
/** Mark the start of a critical section
|
/** Mark the start of a critical section
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
MBED_DEPRECATED_SINCE("mbed-os-5.8",
|
||||||
|
"This function is inconsistent with RAII and is being removed in the future."
|
||||||
|
"Replaced by static function CriticalSectionLock::enable.")
|
||||||
void lock()
|
void lock()
|
||||||
{
|
{
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
|
@ -66,10 +80,27 @@ public:
|
||||||
/** Mark the end of a critical section
|
/** Mark the end of a critical section
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
MBED_DEPRECATED_SINCE("mbed-os-5.8",
|
||||||
|
"This function is inconsistent with RAII and is being removed in the future."
|
||||||
|
"Replaced by static function CriticalSectionLock::disable.")
|
||||||
void unlock()
|
void unlock()
|
||||||
{
|
{
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Mark the start of a critical section
|
||||||
|
*/
|
||||||
|
static void enable()
|
||||||
|
{
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mark the end of a critical section
|
||||||
|
*/
|
||||||
|
static void disable()
|
||||||
|
{
|
||||||
|
core_util_critical_section_exit();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
Loading…
Reference in New Issue