diff options
| author | gingerBill <bill@gingerbill.org> | 2023-01-12 12:59:09 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-01-12 12:59:09 +0000 |
| commit | b470ceb4705477ef42a1efc2c8beb5e3ceef2f88 (patch) | |
| tree | eab473b3853eb6f147b4c3033701537275a24aec /src/queue.cpp | |
| parent | c15db051999e51f5c8ecc45fb084e6fb76c9b5c2 (diff) | |
Correct `mpsc_dequeue`
Diffstat (limited to 'src/queue.cpp')
| -rw-r--r-- | src/queue.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/queue.cpp b/src/queue.cpp index 845f87310..d3fd69c52 100644 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -69,10 +69,13 @@ gb_internal bool mpsc_dequeue(MPSCQueue<T> *q, T *value_) { if (next) { q->tail.store(next, std::memory_order_relaxed); // `tail` is now "dead" and needs to be "freed" - if (*value_) *value_ = next->value; + tail->value = next->value; + T value = tail->value; + if (value_) *value_ = value; q->count.fetch_sub(1, std::memory_order_acq_rel); return true; } + GB_ASSERT(q->count.load(std::memory_order_acquire) == 0); return false; } |