Lock-free queue enqueue.

This commit is contained in:
Bartosz Taudul
2020-01-02 22:23:58 +01:00
parent 6b64fbc3be
commit 92fded825e
+52
View File
@@ -68,6 +68,34 @@ public:
tracy_force_inline void PrepareThread();
tracy_force_inline void CleanupThread();
tracy_force_inline char* PrepareNext( char*& nextPtr, size_t sz )
{
auto tailBlk = m_tail.load();
auto tail = tailBlk->tail.load();
assert( tail >= tailBlk->data );
auto np = tail + sz;
if( np <= tailBlk->dataEnd )
{
nextPtr = np;
return tail;
}
else
{
tailBlk = NextBlock( tailBlk );
tail = tailBlk->tail.load();
nextPtr = tail + sz;
return tail;
}
}
tracy_force_inline void CommitNext( char* nextPtr )
{
auto tailBlk = m_tail.load();
tailBlk->tail.store( nextPtr );
}
tracy_no_inline LfqBlock* NextBlock( LfqBlock* tailBlk );
std::atomic<LfqProducerImpl*> m_next;
std::atomic<bool> m_active, m_available;
@@ -94,6 +122,17 @@ public:
LfqProducer& operator=( LfqProducer&& ) noexcept;
tracy_force_inline char* PrepareNext( char*& nextPtr, size_t sz )
{
return m_prod->PrepareNext( nextPtr, sz );
}
tracy_force_inline void CommitNext( char* nextPtr )
{
m_prod->CommitNext( nextPtr );
}
LfqProducer( const LfqProducer& ) = delete;
LfqProducer( LfqProducer&& ) = delete;
@@ -297,6 +336,19 @@ tracy_force_inline void LfqProducerImpl::CleanupThread()
m_queue->ReleaseBlocks( blk );
}
tracy_no_inline LfqBlock* LfqProducerImpl::NextBlock( LfqBlock* tailBlk )
{
auto next = m_queue->GetFreeBlock();
assert( next );
assert( next->next.load() == nullptr );
assert( tailBlk->next.load() == nullptr );
next->thread = m_thread;
tailBlk->next.store( next );
m_tail.store( next );
return next;
}
}
#endif