mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-01 03:53:33 +00:00
f1dfa4bdfa
https://justine.lol/cosmopolitan/documentation.html should now contain a lot of functions that had been missing previously due to not having them
26 lines
856 B
C
26 lines
856 B
C
#include "third_party/chibicc/test/test.h"
|
|
|
|
#define SPINLOCK(lock) \
|
|
do { \
|
|
for (;;) { \
|
|
typeof(*(lock)) x; \
|
|
__atomic_load(lock, &x, __ATOMIC_RELAXED); \
|
|
if (!x && !__sync_lock_test_and_set(lock, 1)) { \
|
|
break; \
|
|
} else { \
|
|
__builtin_ia32_pause(); \
|
|
} \
|
|
} \
|
|
} while (0)
|
|
|
|
#define SPUNLOCK(lock) __sync_lock_release(lock)
|
|
|
|
_Alignas(64) char lock;
|
|
|
|
main() {
|
|
ASSERT(0, lock);
|
|
SPINLOCK(&lock);
|
|
ASSERT(1, lock);
|
|
SPUNLOCK(&lock);
|
|
ASSERT(0, lock);
|
|
}
|