Skip to content

Commit 2a0a085

Browse files
committed
[gcc] Add definition for __atomic_test_and_set for GCC14
1 parent 4ff8428 commit 2a0a085

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

ext/gcc/atomic.cpp.in

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,27 @@
1616
*
1717
* We ignore the memory order, since the runtime switching takes longer than
1818
* the DMB instruction.
19+
*
20+
* These functions cannot be inlined, since the compiler builtins are named the
21+
* same. Terrible design really.
1922
*/
2023

24+
// ============================ atomics for bools ============================
25+
extern "C" bool
26+
__atomic_test_and_set(volatile void *ptr, int /*memorder*/)
27+
{
28+
bool value{};
29+
__modm_atomic_pre_barrier(__ATOMIC_SEQ_CST);
30+
{
31+
modm::atomic::Lock _;
32+
value = *reinterpret_cast<volatile bool*>(ptr);
33+
*reinterpret_cast<volatile bool*>(ptr) = true;
34+
}
35+
__modm_atomic_post_barrier(__ATOMIC_SEQ_CST);
36+
return value;
37+
}
38+
2139
// ============================ atomics for arrays ============================
22-
// These functions cannot be inlined, since the compiler builtins are named the
23-
// same. Terrible design really.
2440
extern "C" void
2541
__atomic_load(unsigned int size, const volatile void *src, void *dest, int /*memorder*/)
2642
{

0 commit comments

Comments
 (0)