blob: 646136cff12c1bcd5ac3fbc5a0b3e1b19d0f6a97 [file] [log] [blame]
#pragma once
#include <stdatomic.h>
struct spinlock {
atomic_flag v;
};
#define SPINLOCK_INIT \
{ \
.v = ATOMIC_FLAG_INIT \
}
static inline void sl_init(struct spinlock *l)
{
*l = (struct spinlock)SPINLOCK_INIT;
}
static inline void sl_lock(struct spinlock *l)
{
while (atomic_flag_test_and_set_explicit(&l->v, memory_order_acquire)) {
/* do nothing */
}
}
static inline void sl_unlock(struct spinlock *l)
{
atomic_flag_clear_explicit(&l->v, memory_order_release);
}