MIRA
|
A spinlock is similar to a mutex and allows thread synchronization of critical sections. More...
#include <thread/Spinlock.h>
Public Member Functions | |
Spinlock () | |
bool | try_lock () |
Tries to lock the spinlock. More... | |
void | lock () |
Locks the spinlock. More... | |
void | sleeplock () |
Locks the spinlock. More... | |
void | unlock () |
Unlocks the spinlock. More... | |
A spinlock is similar to a mutex and allows thread synchronization of critical sections.
However, it is more efficient than a mutex since calls of kernel space methods are avoided. Nevertheless, the disadvantage of a spinlock is, that it requires CPU time while it is waiting to acquire the lock. It therefore should be used only to protect critical sections, where not much time is spent, to reduce the possible wait time.
|
inline |
|
inline |
Tries to lock the spinlock.
Returns true, if the lock was acquired, otherwise false. This method returns immediately.
|
inline |
Locks the spinlock.
If it is already locked, the method blocks, until the lock can be acquired.
|
inline |
Locks the spinlock.
In contrast to lock(), this method relinquishes the CPU, while waiting for the lock.
|
inline |
Unlocks the spinlock.