50 mData.Resize(size + 1);
59 const auto currentWriteIndex = mWriteIndex.load(std::memory_order_relaxed);
60 const auto nextWriteIndex = Increment(currentWriteIndex);
61 if(nextWriteIndex != mReadIndex.load(std::memory_order_acquire))
63 mData.Get()[currentWriteIndex] = item;
64 mWriteIndex.store(nextWriteIndex, std::memory_order_release);
76 const auto currentReadIndex = mReadIndex.load(std::memory_order_relaxed);
77 if(currentReadIndex == mWriteIndex.load(std::memory_order_acquire))
81 item = mData.Get()[currentReadIndex];
82 mReadIndex.store(Increment(currentReadIndex), std::memory_order_release);
90 template <
typename... Args>
93 const auto currentWriteIndex = mWriteIndex.load(std::memory_order_relaxed);
94 const auto nextWriteIndex = Increment(currentWriteIndex);
95 if(nextWriteIndex != mReadIndex.load(std::memory_order_acquire))
97 mData.Get()[currentWriteIndex] = T(args...);
98 mWriteIndex.store(nextWriteIndex, std::memory_order_release);
108 size_t write = mWriteIndex.load(std::memory_order_acquire);
109 size_t read = mReadIndex.load(std::memory_order_relaxed);
111 return (read > write) ? mData.GetSize() - (read - write) : write - read;
120 const auto currentReadIndex = mReadIndex.load(std::memory_order_relaxed);
121 return mData.Get()[currentReadIndex];
129 return (mWriteIndex.load() == mReadIndex.load());
137 const auto nextWriteIndex = Increment(mWriteIndex.load());
138 return (nextWriteIndex == mReadIndex.load());
145 size_t Increment(
size_t idx)
const
147 return (idx + 1) % (mData.GetSize());
150 WDL_TypedBuf<T> mData;
151 std::atomic<size_t> mWriteIndex{0};
152 std::atomic<size_t> mReadIndex{0};
A lock-free SPSC queue used to transfer data between threads based on MLQueue.h by Randy Jones based ...
size_t ElementsAvailable() const
IPlugQueue(int size)
IPlugQueue constructor.
bool PushFromArgs(Args ...args)