diff options
author | Chris Robinson <[email protected]> | 2016-11-25 23:25:16 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-11-25 23:25:16 -0800 |
commit | 02a6031d03870847aa6b11628b80585004b45194 (patch) | |
tree | 498d1aaa144ac135653a153fc2986acaee7d1541 /common | |
parent | ea82a6d19ef39679afd8a83f069dcd12afe20e40 (diff) |
Use atomic flags for boolean atomic locks
Diffstat (limited to 'common')
-rw-r--r-- | common/rwlock.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/common/rwlock.c b/common/rwlock.c index f1a86fa6..67cf3acf 100644 --- a/common/rwlock.c +++ b/common/rwlock.c @@ -11,19 +11,19 @@ /* A simple spinlock. Yield the thread while the given integer is set by * another. Could probably be improved... */ #define LOCK(l) do { \ - while(ATOMIC_EXCHANGE(int, &(l), true, almemory_order_acq_rel) == true) \ + while(ATOMIC_FLAG_TEST_AND_SET(&(l), almemory_order_acq_rel) == true) \ althrd_yield(); \ } while(0) -#define UNLOCK(l) ATOMIC_STORE(&(l), false, almemory_order_release) +#define UNLOCK(l) ATOMIC_FLAG_CLEAR(&(l), almemory_order_release) void RWLockInit(RWLock *lock) { InitRef(&lock->read_count, 0); InitRef(&lock->write_count, 0); - ATOMIC_INIT(&lock->read_lock, false); - ATOMIC_INIT(&lock->read_entry_lock, false); - ATOMIC_INIT(&lock->write_lock, false); + ATOMIC_FLAG_CLEAR(&lock->read_lock, almemory_order_relaxed); + ATOMIC_FLAG_CLEAR(&lock->read_entry_lock, almemory_order_relaxed); + ATOMIC_FLAG_CLEAR(&lock->write_lock, almemory_order_relaxed); } void ReadLock(RWLock *lock) |