Go to the documentation of this file.
27 #ifndef _AKFIFOQUEUE_H
28 #define _AKFIFOQUEUE_H
36 template<
typename T, T TDEFAULT,
class TAlloc = ArrayPoolDefault>
43 , m_uQueueIndexMask(0)
61 AKASSERT((in_uMaxEntries & (in_uMaxEntries - 1)) == 0);
63 m_uQueueIndexMask = in_uMaxEntries - 1;
67 m_buffer = (FifoQueueEntry*)TAlloc::Alloc(
sizeof(FifoQueueEntry) * in_uMaxEntries);
68 if (m_buffer ==
nullptr)
74 for (
AkUInt32 i = 0; i < in_uMaxEntries; ++i)
76 m_buffer[i].value = TDEFAULT;
103 const AkUInt64 uQueueIndexMask = m_uQueueIndexMask;
104 FifoQueueEntry* pBuffer = m_buffer;
111 if (sequenceDelta == 0)
118 else if (sequenceDelta < 0)
131 pBuffer[writePos & uQueueIndexMask].value = in_value;
132 AkAtomicStore64(&pBuffer[writePos & uQueueIndexMask].uSequence, writePos + 1);
140 const AkInt64 uQueueIndexMask = m_uQueueIndexMask;
141 FifoQueueEntry* pBuffer = m_buffer;
146 AkInt64 sequenceDelta =
AkAtomicLoad64(&pBuffer[readPos & uQueueIndexMask].uSequence) - (readPos + 1);
148 if (sequenceDelta == 0)
156 else if (sequenceDelta < 0)
168 io_value = pBuffer[readPos & uQueueIndexMask].value;
169 AkAtomicStore64(&pBuffer[readPos & uQueueIndexMask].uSequence, readPos + m_uQueueIndexMask + 1);
178 AkInt64 sequenceDelta =
AkAtomicLoad64(&m_buffer[readPos & m_uQueueIndexMask].uSequence) - (readPos + 1);
179 return sequenceDelta < 0;
183 struct FifoQueueEntry
192 FifoQueueEntry* m_buffer;
202 #endif // _AKFIFOQUEUE_H
AKSOUNDENGINE_API void Free(AkMemPoolId in_poolId, void *in_pMemAddress)
AKRESULT
Standard function call result.
bool Dequeue(T &io_value)
@ AK_Success
The operation was successful.
bool Empty()
Checks if there is a value available to be dequeued.
#define AKASSERT(Condition)
AK_NODISCARD bool Enqueue(T in_value)
int64_t AkInt64
Signed 64-bit integer.
uint64_t AkUInt64
Unsigned 64-bit integer.
uint32_t AkUInt32
Unsigned 32-bit integer.
@ AK_InsufficientMemory
Memory error.
AKRESULT Init(AkUInt32 in_uMaxEntries)
Tell us about your project. We're here to help.
Register your project and we'll help you get started with no strings attached!
Get started with Wwise