Skip to content

Commit c192906

Browse files
committed
Changed ReentrantGuard to be quasi-thread-safe since it mostly acts as an illegal concurrency detector most of the time (issue #110)
1 parent eb1925d commit c192906

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

readerwriterqueue.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
108108
,dequeuing(false)
109109
#endif
110110
{
111-
assert(size > 0);
112111
assert(MAX_BLOCK_SIZE == ceilToPow2(MAX_BLOCK_SIZE) && "MAX_BLOCK_SIZE must be a power of 2");
113112
assert(MAX_BLOCK_SIZE >= 2 && "MAX_BLOCK_SIZE must be at least 2");
114113

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

691690
private:
692-
bool& inSection;
691+
weak_atomic<bool>& inSection;
693692
};
694693
#endif
695694

@@ -750,8 +749,8 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
750749
size_t largestBlockSize;
751750

752751
#ifndef NDEBUG
753-
bool enqueuing;
754-
mutable bool dequeuing;
752+
weak_atomic<bool> enqueuing;
753+
mutable weak_atomic<bool> dequeuing;
755754
#endif
756755
};
757756

0 commit comments

Comments
 (0)