/* * spinlock.c * * Sung-Eun Choi (sungeun@cs.washington.edu) * Autumn 1996 * */ #include #include "minithread.h" void spinlock_init(tas_lock_t *l) { atomic_clear(l); /* reset the lock */ } void spinlock_unlock(tas_lock_t *l) { atomic_clear(l); /* give up the lock */ } void spinlock_lock(tas_lock_t *l) { while (atomic_test_and_set(l)) { /* while someone else has the lock */ minithread_yield(); /* yield and let others do useful work */ } }