Skip to content

Commit

Permalink
fixed concurrentqueue compilation bug on gcc 4.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rchikhi committed Jan 10, 2015
1 parent 1360116 commit be7bda8
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions thirdparty/concurrentqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,33 @@ class ConcurrentQueue
return false;
}
}

/* Rayan: duplicating that code to remove the template fixes a compilation error on my gcc 4.9.1 */
inline bool is_empty_explicit() const
{
if (BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) {
// Check flags
for (size_t i = 0; i < BLOCK_SIZE; ++i) {
if (!emptyFlags[i].load(std::memory_order_relaxed)) {
return false;
}
}

// Aha, empty; make sure we have all other memory effects that happened before the empty flags were set
std::atomic_thread_fence(std::memory_order_acquire);
return true;
}
else {
// Check counter
if (elementsCompletelyDequeued.load(std::memory_order_relaxed) == BLOCK_SIZE) {
std::atomic_thread_fence(std::memory_order_acquire);
return true;
}
assert(elementsCompletelyDequeued.load(std::memory_order_relaxed) <= BLOCK_SIZE);
return false;
}
}


// Returns true if the block is now empty (does not apply in explicit context)
template<InnerQueueContext context>
Expand Down Expand Up @@ -1535,7 +1562,7 @@ class ConcurrentQueue
auto block = this->tailBlock;
do {
block = block->next;
if (block->template is_empty<explicit_context>()) {
if (block->is_empty_explicit()) {
continue;
}

Expand Down Expand Up @@ -1583,7 +1610,7 @@ class ConcurrentQueue
// We reached the end of a block, start a new one
auto startBlock = this->tailBlock;
auto originalBlockIndexSlotsUsed = pr_blockIndexSlotsUsed;
if (this->tailBlock != nullptr && this->tailBlock->next->template is_empty<explicit_context>()) {
if (this->tailBlock != nullptr && this->tailBlock->next->is_empty_explicit()) {
// We can re-use the block ahead of us, it's empty!
this->tailBlock = this->tailBlock->next;
this->tailBlock->template reset_empty<explicit_context>();
Expand Down Expand Up @@ -1788,7 +1815,7 @@ class ConcurrentQueue
index_t currentTailIndex = (startTailIndex - 1) & ~static_cast<index_t>(BLOCK_SIZE - 1);
if (blockBaseDiff > 0) {
// Allocate as many blocks as possible from ahead
while (blockBaseDiff > 0 && this->tailBlock != nullptr && this->tailBlock->next != firstAllocatedBlock && this->tailBlock->next->template is_empty<explicit_context>()) {
while (blockBaseDiff > 0 && this->tailBlock != nullptr && this->tailBlock->next != firstAllocatedBlock && this->tailBlock->next->is_empty_explicit()) {
blockBaseDiff -= static_cast<index_t>(BLOCK_SIZE);
currentTailIndex += static_cast<index_t>(BLOCK_SIZE);

Expand Down

5 comments on commit be7bda8

@cameron314
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've committed a fix for the same bug on the master. See the issue and the Stack Overflow question it spawned.

@rchikhi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet, thanks for the explanation!
I had to make other modifications to concurrentqueue to get it to compile on gcc 4.7:
c67c60f (+ 0cdb3b9)

@cameron314
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. I'll work in some fixes for g++ 4.7 too soon, I just didn't have that version installed to test with, sorry. Don't be shy about opening issues on my repo about this stuff :-)

@cameron314
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a commit to the master that should fix the issues you were having with g++ 4.7. Cheers!

@rchikhi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice!

Please sign in to comment.