Skip to content

Commit a719840

Browse files
committed
Add bool atomics
1 parent f8e3f5d commit a719840

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

platform/mbed_critical.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ void core_util_critical_section_exit(void)
100100
}
101101
}
102102

103+
/* Inline bool implementations in the header use uint8_t versions to manipulate the bool */
104+
MBED_STATIC_ASSERT(sizeof(bool) == sizeof(uint8_t), "Surely bool is a byte");
105+
103106
#if MBED_EXCLUSIVE_ACCESS
104107

105108
/* Supress __ldrex and __strex deprecated warnings - "#3731-D: intrinsic is deprecated" */

platform/mbed_critical.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ bool core_util_atomic_cas_u32(volatile uint32_t *ptr, uint32_t *expectedCurrentV
211211
/** \copydoc core_util_atomic_cas_u8 */
212212
bool core_util_atomic_cas_u64(volatile uint64_t *ptr, uint64_t *expectedCurrentValue, uint64_t desiredValue);
213213

214+
/** \copydoc core_util_atomic_cas_u8 */
215+
MBED_FORCEINLINE bool core_util_atomic_cas_bool(volatile bool *ptr, bool *expectedCurrentValue, bool desiredValue)
216+
{
217+
return (bool)core_util_atomic_cas_u8((volatile uint8_t *)ptr, (uint8_t *)expectedCurrentValue, desiredValue);
218+
}
219+
214220
/** \copydoc core_util_atomic_cas_u8 */
215221
bool core_util_atomic_cas_ptr(void *volatile *ptr, void **expectedCurrentValue, void *desiredValue);
216222

@@ -257,6 +263,18 @@ MBED_FORCEINLINE uint32_t core_util_atomic_load_u32(const volatile uint32_t *val
257263
*/
258264
uint64_t core_util_atomic_load_u64(const volatile uint64_t *valuePtr);
259265

266+
/**
267+
* Atomic load.
268+
* @param valuePtr Target memory location.
269+
* @return The loaded value.
270+
*/
271+
MBED_FORCEINLINE bool core_util_atomic_load_bool(const volatile bool *valuePtr)
272+
{
273+
bool value = *valuePtr;
274+
MBED_BARRIER();
275+
return value;
276+
}
277+
260278
/**
261279
* Atomic load.
262280
* @param valuePtr Target memory location.
@@ -312,6 +330,18 @@ MBED_FORCEINLINE void core_util_atomic_store_u32(volatile uint32_t *valuePtr, ui
312330
*/
313331
void core_util_atomic_store_u64(volatile uint64_t *valuePtr, uint64_t desiredValue);
314332

333+
/**
334+
* Atomic store.
335+
* @param valuePtr Target memory location.
336+
* @param desiredValue The value to store.
337+
*/
338+
MBED_FORCEINLINE void core_util_atomic_store_bool(volatile bool *valuePtr, bool desiredValue)
339+
{
340+
MBED_BARRIER();
341+
*valuePtr = desiredValue;
342+
MBED_BARRIER();
343+
}
344+
315345
/**
316346
* Atomic store.
317347
* @param valuePtr Target memory location.

0 commit comments

Comments
 (0)