Skip to content

Commit d0adb12

Browse files
committed
Fix an extremely rare bug.
1 parent a655b65 commit d0adb12

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

include/daking/MPSC_queue.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,14 @@ namespace daking {
666666

667667
DAKING_ALWAYS_INLINE node_t* _allocate() {
668668
node_t*& thread_local_node_list = _get_thread_local_node_list();
669-
if (!thread_local_node_list) DAKING_UNLIKELY {
669+
size_type& thread_local_node_size = _get_thread_local_node_size();
670+
if (thread_local_node_size == 0) DAKING_UNLIKELY {
670671
while (!global_chunk_stack_.try_pop(thread_local_node_list)) {
671672
_reserve_global_internal();
672673
}
674+
thread_local_node_size = thread_local_capacity;
673675
}
676+
thread_local_node_size--;
674677
DAKING_TSAN_ANNOTATE_ACQUIRE(thread_local_node_list);
675678
DAKING_TSAN_ANNOTATE_ACQUIRE(thread_local_node_list->next_);
676679
node_t* res = std::exchange(thread_local_node_list, thread_local_node_list->next_.load(std::memory_order_relaxed));

0 commit comments

Comments
 (0)