Skip to content

Use relaxed loads - #10

Merged
sbooth merged 5 commits into
mainfrom
relax
Jul 10, 2026
Merged

Use relaxed loads#10
sbooth merged 5 commits into
mainfrom
relax

Conversation

@sbooth

@sbooth sbooth commented Jul 10, 2026

Copy link
Copy Markdown
Owner

There are no release stores for the acquire loads to pair with.

Copilot AI review requested due to automatic review settings July 10, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_acquire loads with std::memory_order_relaxed in emptySlots(), isFull(), occupiedSlots(), and isEmpty().
  • 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 thread Sources/CXXMessageQueue/include/mpsc/MessageQueue.hpp Outdated
Comment thread Sources/CXXMessageQueue/include/mpsc/MessageQueue.hpp
Comment thread Sources/CXXMessageQueue/include/mpsc/MessageQueue.hpp Outdated
Comment thread Sources/CXXMessageQueue/include/mpsc/MessageQueue.hpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

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;
}
@sbooth
sbooth merged commit 8d52853 into main Jul 10, 2026
7 checks passed
@sbooth
sbooth deleted the relax branch July 10, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants