Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::common::Spinlock Class Reference

Enables a resource to be used by only one instance at a time through locking and unlocking. More...

#include <spinlock.h>

Public Member Functions

void lock ()
 Lock the spinlock once it is available.
 
void unlock ()
 Unlock the spinlock.
 
bool is_locked () const
 Check if the spinlock is locked.
 
void acquire ()
 Acquire the spinlock: wait until the lock is available, spinning until that happens.
 
void release ()
 Release the spinlock.
 

Detailed Description

Enables a resource to be used by only one instance at a time through locking and unlocking.

Definition at line 21 of file spinlock.h.

Member Function Documentation

◆ acquire()

void Spinlock::acquire ( )

Acquire the spinlock: wait until the lock is available, spinning until that happens.

Definition at line 51 of file spinlock.cpp.

51 {
52 while (__atomic_test_and_set(&m_locked, __ATOMIC_ACQUIRE))
53 asm("nop");
54}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22

Referenced by lock().

◆ is_locked()

bool Spinlock::is_locked ( ) const

Check if the spinlock is locked.

Returns
True if the spinlock is locked, false otherwise

Definition at line 43 of file spinlock.cpp.

43 {
44 return m_locked;
45}

◆ lock()

◆ release()

void Spinlock::release ( )

Release the spinlock.

Definition at line 59 of file spinlock.cpp.

59 {
61}

Referenced by unlock().

◆ unlock()


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