MMCore: simplify notificationQueueMutex_#908
Merged
marktsuchida merged 1 commit intomicro-manager:mainfrom Apr 7, 2026
Merged
Conversation
- Switch from std::shared_mutex to plain std::mutex, because this
uncontended and briefly held mutex is unlikely to benefit from a
read-write lock (if anything, shared_mutex may have more overhead)
- In postNotification(), only hold notificationQueueMutex_ while making
a copy of the shared_ptr to the queue, and perform the push outside
it. This is safe because:
- If the queue doesn't exist, no behavior change (no push)
- If the queue exists and a callback swap is happening concurrently,
the queue is not swapped so no notifications are lost
- If the queue exists and a callback unregister is happening
concurrently, we have a slight increase in concurrency but no
behavioral change because the queue is dropped after joining the
delivery thread; the concurrently posted notifications are dropped
in either case and this is not a problem
(Assisted by Claude Code; any errors are mine.)
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.
Minor cleanup/simplification.
Switch from std::shared_mutex to plain std::mutex, because this uncontended and briefly held mutex is unlikely to benefit from a read-write lock (if anything, shared_mutex may have more overhead)
In postNotification(), only hold notificationQueueMutex_ while making a copy of the shared_ptr to the queue, and perform the push outside it. This is safe because: