Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
spinlock Class Reference

Intended for locking of resources that are only lightly contended and locked for very short times, can be used with std::lock_guard. More...

#include <spinlock.h>

Public Member Functions

 ~spinlock ()
 
void lock ()
 
void unlock ()
 

Private Attributes

std::atomic_flag flag = ATOMIC_FLAG_INIT
 

Detailed Description

Intended for locking of resources that are only lightly contended and locked for very short times, can be used with std::lock_guard.

Definition at line 21 of file spinlock.h.

Constructor & Destructor Documentation

◆ ~spinlock()

spinlock::~spinlock ( )
inline

Definition at line 25 of file spinlock.h.

25{ }

Member Function Documentation

◆ lock()

void spinlock::lock ( )
inline

Definition at line 27 of file spinlock.h.

28 {
29 for(unsigned i = 0; flag.test_and_set(std::memory_order_acquire); ++i)
30 if(i & 1) std::this_thread::yield();
31 }
std::atomic_flag flag
Definition: spinlock.h:23

References flag.

Referenced by RealtimeEffectManager::AllListsLock::AllListsLock().

Here is the caller graph for this function:

◆ unlock()

void spinlock::unlock ( )
inline

Definition at line 33 of file spinlock.h.

34 {
35 flag.clear(std::memory_order_release);
36 }

References flag.

Referenced by RealtimeEffectManager::AllListsLock::Reset().

Here is the caller graph for this function:

Member Data Documentation

◆ flag

std::atomic_flag spinlock::flag = ATOMIC_FLAG_INIT
private

Definition at line 23 of file spinlock.h.

Referenced by lock(), and unlock().


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