mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-12 19:31:47 +00:00
Separate enqueue allocation functionality.
This commit is contained in:
parent
16a49356a0
commit
439a23049d
@ -1901,10 +1901,8 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<AllocationMode allocMode>
|
template<AllocationMode allocMode>
|
||||||
inline T* enqueue_begin()
|
inline void enqueue_begin_alloc()
|
||||||
{
|
{
|
||||||
pr_currentTailIndex = this->tailIndex.load(std::memory_order_relaxed);
|
|
||||||
if ((pr_currentTailIndex & static_cast<index_t>(BLOCK_SIZE - 1)) == 0) {
|
|
||||||
// We reached the end of a block, start a new one
|
// We reached the end of a block, start a new one
|
||||||
if (this->tailBlock != nullptr && this->tailBlock->next->ConcurrentQueue::Block::template is_empty<explicit_context>()) {
|
if (this->tailBlock != nullptr && this->tailBlock->next->ConcurrentQueue::Block::template is_empty<explicit_context>()) {
|
||||||
// We can re-use the block ahead of us, it's empty!
|
// We can re-use the block ahead of us, it's empty!
|
||||||
@ -1928,7 +1926,7 @@ private:
|
|||||||
// We can't enqueue in another block because there's not enough leeway -- the
|
// We can't enqueue in another block because there's not enough leeway -- the
|
||||||
// tail could surpass the head by the time the block fills up! (Or we'll exceed
|
// tail could surpass the head by the time the block fills up! (Or we'll exceed
|
||||||
// the size limit, if the second part of the condition was true.)
|
// the size limit, if the second part of the condition was true.)
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
// We're going to need a new block; check that the block index has room
|
// We're going to need a new block; check that the block index has room
|
||||||
if (pr_blockIndexRaw == nullptr || pr_blockIndexSlotsUsed == pr_blockIndexSize) {
|
if (pr_blockIndexRaw == nullptr || pr_blockIndexSlotsUsed == pr_blockIndexSize) {
|
||||||
@ -1937,14 +1935,14 @@ private:
|
|||||||
// the initial allocation failed in the constructor.
|
// the initial allocation failed in the constructor.
|
||||||
|
|
||||||
if (allocMode == CannotAlloc || !new_block_index(pr_blockIndexSlotsUsed)) {
|
if (allocMode == CannotAlloc || !new_block_index(pr_blockIndexSlotsUsed)) {
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a new block in the circular linked list
|
// Insert a new block in the circular linked list
|
||||||
auto newBlock = this->parent->ConcurrentQueue::template requisition_block<allocMode>();
|
auto newBlock = this->parent->ConcurrentQueue::template requisition_block<allocMode>();
|
||||||
if (newBlock == nullptr) {
|
if (newBlock == nullptr) {
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
#if MCDBGQ_TRACKMEM
|
#if MCDBGQ_TRACKMEM
|
||||||
newBlock->owner = this;
|
newBlock->owner = this;
|
||||||
@ -1969,9 +1967,18 @@ private:
|
|||||||
pr_blockIndexFront = (pr_blockIndexFront + 1) & (pr_blockIndexSize - 1);
|
pr_blockIndexFront = (pr_blockIndexFront + 1) & (pr_blockIndexSize - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enqueue
|
template<AllocationMode allocMode>
|
||||||
|
inline T* enqueue_begin()
|
||||||
|
{
|
||||||
|
pr_currentTailIndex = this->tailIndex.load(std::memory_order_relaxed);
|
||||||
|
if ((pr_currentTailIndex & static_cast<index_t>(BLOCK_SIZE - 1)) != 0) {
|
||||||
return (*this->tailBlock)[pr_currentTailIndex];
|
return (*this->tailBlock)[pr_currentTailIndex];
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this->enqueue_begin_alloc<allocMode>();
|
||||||
|
return (*this->tailBlock)[pr_currentTailIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void enqueue_finish()
|
inline void enqueue_finish()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user