26 lines
643 B
C
Raw Normal View History

2018-02-24 06:20:45 -08:00
#ifndef EXOSPHERE_LOCK_H
#define EXOSPHERE_LOCK_H
#include <stdatomic.h>
2018-02-24 06:20:45 -08:00
#include <stdbool.h>
/* Simple atomics driver for Exosphere. */
/* Acquire a lock. */
static inline void lock_acquire(atomic_flag *flag) {
while (atomic_flag_test_and_set_explicit(flag, memory_order_acquire)) {
2018-02-24 06:20:45 -08:00
/* Wait to acquire lock. */
}
}
/* Release a lock. */
static inline void lock_release(atomic_flag *flag) {
atomic_flag_clear_explicit(flag, memory_order_release);
2018-02-24 06:20:45 -08:00
}
/* Try to acquire a lock. */
static inline bool lock_try_acquire(atomic_flag *flag) {
return atomic_flag_test_and_set_explicit(flag, memory_order_acquire);
2018-02-24 06:20:45 -08:00
}
#endif