Expand description
SMP-supported spinlock.
The implementing unicore spinlock uniprocessor is simple; it just requires preventing thread preemption while holding a lock. By disabling preemption of the lock-holding thread, other threads cannot access shared resource as they can’t be scheduled.
However, when it comes to multiprocessor, disabling preemption is not
sufficient; as multiple threads run concurrently in different cores, they
can access shared resource at the same time even when a core disable
preemption. Therefore, to acquire a lock on multi-processor, a processor 1)
polls a variable that represents a value is locked or not 2) set the
variable when a thread holds the lock, and 3) unset the variable when the
thread unlock.
The step 1 and 2 must be executed ATOMICALLY with the atomic read-modify-write instructions of the CPU.
This module introduce the support of the SMP-supported spinlock in KeOS.
Structs§
- Spin
Lock - A mutual exclusion primitive useful for protecting shared data
- Spin
Lock Guard - An implementation of a “scoped lock” of a spinlock. When this structure is dropped (falls out of scope) without unlock, panic occurs.
- Would
Block - The lock could not be acquired at this time because the operation would otherwise block.