KiCad PCB EDA Suite
KISPINLOCK Class Reference

A trivial spinlock implementation with no optimization. More...

#include <spinlock.h>

Public Member Functions

 KISPINLOCK ()
 
void lock ()
 
bool try_lock ()
 
void unlock ()
 
bool test ()
 

Private Attributes

std::atomic< bool > m_lock
 

Detailed Description

A trivial spinlock implementation with no optimization.

Don't use if congestion is expected!

Definition at line 29 of file spinlock.h.

Constructor & Destructor Documentation

◆ KISPINLOCK()

KISPINLOCK::KISPINLOCK ( )
inline

Definition at line 32 of file spinlock.h.

32  :
33  m_lock( false )
34  {}
std::atomic< bool > m_lock
Definition: spinlock.h:57

Member Function Documentation

◆ lock()

void KISPINLOCK::lock ( )
inline

Definition at line 36 of file spinlock.h.

37  {
38  while( m_lock.exchange( true, std::memory_order_acquire ) );
39  }
std::atomic< bool > m_lock
Definition: spinlock.h:57

References m_lock.

◆ test()

bool KISPINLOCK::test ( )
inline

Definition at line 51 of file spinlock.h.

52  {
53  return m_lock.load( std::memory_order_acquire );
54  }
std::atomic< bool > m_lock
Definition: spinlock.h:57

References m_lock.

◆ try_lock()

bool KISPINLOCK::try_lock ( )
inline

Definition at line 41 of file spinlock.h.

42  {
43  return !m_lock.exchange( true, std::memory_order_acquire );
44  }
std::atomic< bool > m_lock
Definition: spinlock.h:57

References m_lock.

◆ unlock()

void KISPINLOCK::unlock ( )
inline

Definition at line 46 of file spinlock.h.

47  {
48  m_lock.store( false, std::memory_order_release );
49  }
std::atomic< bool > m_lock
Definition: spinlock.h:57

References m_lock.

Member Data Documentation

◆ m_lock

std::atomic<bool> KISPINLOCK::m_lock
private

Definition at line 57 of file spinlock.h.

Referenced by lock(), test(), try_lock(), and unlock().


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