Spinlocks are a much lighter weight (though less efficient) way to prevent contention between threads. In KOS they can also allow you to prevent contention between interrupt handlers and normal user code while still providing performance by allowing critical sections that still allow interrupts to happen.
The data type for a spinlock is spinlock_t. This value can either be initialized statically with SPINLOCK_INITIALIZER, or it can be initialized programmatically with spinlock_init.
These are usually implemented as macros for speed.
Initializes the given spinlock. It will be unlocked initially.
Attempts to lock the spinlock. If it is already locked then the function will not return until the caller owns the lock.
Unlocks the given spinlock, if it's locked. Note that any thread can unlock any spinlock - there is no lock ownership.
Returns non-zero if the given lock is locked. This is helpful for, e.g., allocating memory inside an interrupt.