Skip to content

Commit

Permalink
Changed ReentrantGuard to be quasi-thread-safe since it mostly acts a…
Browse files Browse the repository at this point in the history
…s an illegal concurrency detector most of the time (issue #110)
  • Loading branch information
cameron314 committed Nov 26, 2020
1 parent eb1925d commit c192906
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions readerwriterqueue.h
Expand Up @@ -108,7 +108,6 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
,dequeuing(false)
#endif
{
assert(size > 0);
assert(MAX_BLOCK_SIZE == ceilToPow2(MAX_BLOCK_SIZE) && "MAX_BLOCK_SIZE must be a power of 2");
assert(MAX_BLOCK_SIZE >= 2 && "MAX_BLOCK_SIZE must be at least 2");

Expand Down Expand Up @@ -676,7 +675,7 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
#ifndef NDEBUG
struct ReentrantGuard
{
AE_NO_TSAN ReentrantGuard(bool& _inSection)
AE_NO_TSAN ReentrantGuard(weak_atomic<bool>& _inSection)
: inSection(_inSection)
{
assert(!inSection && "Concurrent (or re-entrant) enqueue or dequeue operation detected (only one thread at a time may hold the producer or consumer role)");
Expand All @@ -689,7 +688,7 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
ReentrantGuard& operator=(ReentrantGuard const&);

private:
bool& inSection;
weak_atomic<bool>& inSection;
};
#endif

Expand Down Expand Up @@ -750,8 +749,8 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
size_t largestBlockSize;

#ifndef NDEBUG
bool enqueuing;
mutable bool dequeuing;
weak_atomic<bool> enqueuing;
mutable weak_atomic<bool> dequeuing;
#endif
};

Expand Down

0 comments on commit c192906

Please sign in to comment.