diff options
Diffstat (limited to 'include/apos/lock.h')
| -rw-r--r-- | include/apos/lock.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/apos/lock.h b/include/apos/lock.h new file mode 100644 index 0000000..b8983fa --- /dev/null +++ b/include/apos/lock.h @@ -0,0 +1,23 @@ +#ifndef LOCK_H +#define LOCK_H + +#include <apos/atomic.h> +typedef atomic_int spinlock_t; + +#include <lock.h> + +static inline void spin_lock(spinlock_t *lck) +{ + do { + while (atomic_load_explicit(lck, memory_order_acquire)) + optional_pause(); + + } while (atomic_exchange_explicit(lck, 1, memory_order_acq_rel)); +} + +static inline void spin_unlock(spinlock_t *lck) +{ + atomic_store_explicit(lck, 0, memory_order_release); +} + +#endif /* LOCK_H */ |
