1 2 3 4 5 6 7 8 9 10 11 12
#include <kernel/spinlock.H> void Spinlock::lock() { uint64_t reservation = __sync_fetch_and_add(&iv_reserve, 1); while(iv_ready != reservation); } void Spinlock::unlock() { __sync_add_and_fetch(&iv_ready, 1); }