Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the memory ordering used by MessageQueue’s occupancy/introspection helpers to use relaxed atomic loads, based on the observation that there are no corresponding release stores on the position atomics to pair with acquire loads.
Changes:
- Replaces
std::memory_order_acquireloads withstd::memory_order_relaxedinemptySlots(),isFull(),occupiedSlots(), andisEmpty(). - Updates/normalizes the API documentation notes for these helpers to emphasize that results are transient snapshots.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
102
to
105
| /// Returns the number of occupied slots in the message queue. | ||
| /// @note The result of this method is only accurate when called from the consumer. | ||
| /// @note The returned value is a transient snapshot and may become stale immediately after return. | ||
| /// @return The number of occupied slots containing messages. | ||
| [[nodiscard]] SizeType occupiedSlots() const noexcept [[clang::nonblocking]]; |
Comment on lines
107
to
110
| /// Returns true if the message queue is empty. | ||
| /// @note The result of this method is only accurate when called from the consumer. | ||
| /// @note The returned value is a transient snapshot and may become stale immediately after return. | ||
| /// @return true if all slots in the queue are empty. | ||
| [[nodiscard]] bool isEmpty() const noexcept [[clang::nonblocking]]; |
Comment on lines
275
to
279
| inline bool MessageQueue<N, C>::isFull() const noexcept { | ||
| const auto writePos = writePosition_.load(std::memory_order_relaxed); | ||
| const auto readPos = readPosition_.load(std::memory_order_acquire); | ||
| const auto readPos = readPosition_.load(std::memory_order_relaxed); | ||
| return (writePos - readPos) == N; | ||
| } |
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.
There are no release stores for the acquire loads to pair with.