Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
LockFreeQueue< T > Class Template Reference

#include <LockFreeQueue.h>

Inheritance diagram for LockFreeQueue< T >:
[legend]
Collaboration diagram for LockFreeQueue< T >:
[legend]

Public Member Functions

 LockFreeQueue (size_t maxLen)
 
 ~LockFreeQueue ()
 
bool Put (const T &msg)
 
bool Get (T &msg)
 
void Clear ()
 

Private Attributes

NonInterfering< std::atomic< size_t > > mStart { 0 }
 
NonInterfering< std::atomic< size_t > > mEnd { 0 }
 
const size_t mBufferSize
 
ArrayOf< T > mBuffer { mBufferSize }
 

Additional Inherited Members

- Static Public Member Functions inherited from SharedNonInterfering< LockFreeQueue< T > >
static std::shared_ptr< LockFreeQueue< T > > make_shared (Args &&...args)
 

Detailed Description

template<typename T>
class LockFreeQueue< T >

Audacity: A Digital Audio Editor

LockFreeQueue.h

Matthieu Hodgkinson Moved from MeterPanel.h

Definition at line 20 of file LockFreeQueue.h.

Constructor & Destructor Documentation

◆ LockFreeQueue()

template<typename T >
LockFreeQueue< T >::LockFreeQueue ( size_t  maxLen)
explicit

Definition at line 41 of file LockFreeQueue.h.

42 : mBufferSize(maxLen)
43{
44 Clear();
45}
const size_t mBufferSize
Definition: LockFreeQueue.h:36

References LockFreeQueue< T >::Clear().

Here is the call graph for this function:

◆ ~LockFreeQueue()

template<typename T >
LockFreeQueue< T >::~LockFreeQueue

Definition at line 48 of file LockFreeQueue.h.

49{
50}

Member Function Documentation

◆ Clear()

template<typename T >
void LockFreeQueue< T >::Clear

Definition at line 52 of file LockFreeQueue.h.

53{
54 mStart.store(0);
55 mEnd.store(0);
56}
NonInterfering< std::atomic< size_t > > mEnd
Definition: LockFreeQueue.h:34
NonInterfering< std::atomic< size_t > > mStart
Definition: LockFreeQueue.h:34

Referenced by LockFreeQueue< T >::LockFreeQueue().

Here is the caller graph for this function:

◆ Get()

template<typename T >
bool LockFreeQueue< T >::Get ( T &  msg)

Definition at line 83 of file LockFreeQueue.h.

84{
85 auto start = mStart.load(std::memory_order_relaxed);
86 auto end = mEnd.load(std::memory_order_acquire);
87 int len = (end + mBufferSize - start) % mBufferSize;
88
89 if (len == 0)
90 return false;
91
92 msg = mBuffer[start];
93 mStart.store((start + 1) % mBufferSize, std::memory_order_release);
94
95 return true;
96}
ArrayOf< T > mBuffer
Definition: LockFreeQueue.h:37
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References details::end().

Here is the call graph for this function:

◆ Put()

template<typename T >
bool LockFreeQueue< T >::Put ( const T &  msg)

Definition at line 60 of file LockFreeQueue.h.

61{
62 auto start = mStart.load(std::memory_order_acquire);
63 auto end = mEnd.load(std::memory_order_relaxed);
64 // mStart can be greater than mEnd because it is all mod mBufferSize
65 assert((end + mBufferSize - start) >= 0);
66 int len = (end + mBufferSize - start) % mBufferSize;
67
68 // Never completely fill the queue, because then the
69 // state is ambiguous (mStart==mEnd)
70 if (len + 1 >= (int)(mBufferSize))
71 return false;
72
73 // wxLogDebug(wxT("Put: %s"), msg.toString());
74
75 mBuffer[end] = msg;
76 mEnd.store((end + 1) % mBufferSize, std::memory_order_release);
77
78 return true;
79}

References details::end().

Here is the call graph for this function:

Member Data Documentation

◆ mBuffer

template<typename T >
ArrayOf<T> LockFreeQueue< T >::mBuffer { mBufferSize }
private

Definition at line 37 of file LockFreeQueue.h.

◆ mBufferSize

template<typename T >
const size_t LockFreeQueue< T >::mBufferSize
private

Definition at line 36 of file LockFreeQueue.h.

◆ mEnd

template<typename T >
NonInterfering<std::atomic<size_t> > LockFreeQueue< T >::mEnd { 0 }
private

Definition at line 34 of file LockFreeQueue.h.

◆ mStart

template<typename T >
NonInterfering<std::atomic<size_t> > LockFreeQueue< T >::mStart { 0 }
private

Definition at line 34 of file LockFreeQueue.h.


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