Move values through BoundedQueue slots#110
Open
vadimskipin wants to merge 1 commit into
Open
Conversation
enqueue moved from its by-value parameter into the slot and dequeue moved the slot value out, where both previously copied. A dequeued slot no longer retains a copy until its next lap, so a T holding a reference (a shared pointer) releases it at hand-off; enqueue's retry-on-full callers keep their argument intact either way.
There was a problem hiding this comment.
Pull request overview
This PR updates BoundedQueue to transfer ownership through slots by moving values into the queue on enqueue and moving values out of the queue on dequeue, instead of copying. This enables earlier release of resources for move-aware types (e.g., smart pointers) when a value is dequeued.
Changes:
- Move
enqueue’s by-value parameter into the target slot (std::move(value)). - Move the slot’s stored value into the output on
dequeue(std::move(slot.value)). - Add
<utility>include to support move operations.
Comments suppressed due to low confidence (1)
include/silk/util/bounded-queue.h:107
dequeueisnoexcept, but*value = std::move(slot.value)may invoke a throwing move assignment where a non-throwing copy assignment would otherwise be used, leading tostd::terminate()for someT. Usingstd::move_if_noexcepthere avoids regressingnoexceptbehavior for such types.
if (dequeuePos.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed))
{
*value = std::move(slot.value);
slot.sequence.store(pos + mask + 1, std::memory_order_release);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
72
to
75
| if (enqueuePos.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed)) | ||
| { | ||
| slot.value = value; | ||
| slot.value = std::move(value); | ||
| slot.sequence.store(pos + 1, std::memory_order_release); |
| if (dequeuePos.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed)) | ||
| { | ||
| *value = slot.value; | ||
| *value = std::move(slot.value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
enqueue moved from its by-value parameter into the slot and dequeue moved the slot value out, where both previously copied. A dequeued slot no longer retains a copy until its next lap, so a T holding a reference (a shared pointer) releases it at hand-off; enqueue's retry-on-full callers keep their argument intact either way.