MIRA
Public Member Functions | List of all members
Spinlock Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Spinlock()

Spinlock ( )
inline

Member Function Documentation

◆ try_lock()

bool try_lock ( )
inline

Tries to lock the spinlock.

Returns true, if the lock was acquired, otherwise false. This method returns immediately.

◆ lock()

void lock ( )
inline

Locks the spinlock.

If it is already locked, the method blocks, until the lock can be acquired.

◆ sleeplock()

void sleeplock ( )
inline

Locks the spinlock.

In contrast to lock(), this method relinquishes the CPU, while waiting for the lock.

◆ unlock()

void unlock ( )
inline

Unlocks the spinlock.


The documentation for this class was generated from the following file: