mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: platform/mbed_critical.h
- Revision:
- 189:f392fc9709a3
- Parent:
- 188:bcfe06ba3d64
--- a/platform/mbed_critical.h Thu Nov 08 11:46:34 2018 +0000 +++ b/platform/mbed_critical.h Wed Feb 20 22:31:08 2019 +0000 @@ -90,6 +90,43 @@ bool core_util_in_critical_section(void); /** + * A lock-free, primitive atomic flag. + * + * Emulate C11's atomic_flag. The flag is initially in an indeterminate state + * unless explicitly initialized with CORE_UTIL_ATOMIC_FLAG_INIT. + */ +typedef struct core_util_atomic_flag { + uint8_t _flag; +} core_util_atomic_flag; + +/** + * Initializer for a core_util_atomic_flag. + * + * Example: + * ~~~ + * core_util_atomic_flag in_progress = CORE_UTIL_ATOMIC_FLAG_INIT; + * ~~~ + */ +#define CORE_UTIL_ATOMIC_FLAG_INIT { 0 } + +/** + * Atomic test and set. + * + * Atomically tests then sets the flag to true, returning the previous value. + * + * @param flagPtr Target flag being tested and set. + * @return The previous value. + */ +bool core_util_atomic_flag_test_and_set(volatile core_util_atomic_flag *flagPtr); + +/** + * Atomic clear. + * + * @param flagPtr Target flag being cleared. + */ +void core_util_atomic_flag_clear(volatile core_util_atomic_flag *flagPtr); + +/** * Atomic compare and set. It compares the contents of a memory location to a * given value and, only if they are the same, modifies the contents of that * memory location to a given new value. This is done as a single atomic