Skip to content

CriticalSectionLock class improvement #5621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions platform/CriticalSectionLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ namespace mbed {
* Usage:
* @code
*
* void f() {
* // some code here
* {
* CriticalSectionLock lock;
* // Code in this block will run with interrupts disabled
* }
* // interrupts will be restored to their previous state
* // RAII style usage
* unsigned int atomic_counter_increment(unsigned int &counter) {
* CriticalSectionLock lock;
* // Code in this block will run with interrupts disabled
* // Interrupts will be restored to their previous state automatically
* // at the end of function scope
* 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
*/
class CriticalSectionLock {
Expand All @@ -56,20 +67,40 @@ class CriticalSectionLock {
}

/** 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()
{
core_util_critical_section_enter();
}

/** 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()
{
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();
}
};

/**@}*/
Expand Down