Skip to content

MMCore: simplify notificationQueueMutex_#908

Merged
marktsuchida merged 1 commit intomicro-manager:mainfrom
marktsuchida:simplify-notification-queue-mutex
Apr 7, 2026
Merged

MMCore: simplify notificationQueueMutex_#908
marktsuchida merged 1 commit intomicro-manager:mainfrom
marktsuchida:simplify-notification-queue-mutex

Conversation

@marktsuchida
Copy link
Copy Markdown
Member

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:

    • 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

- 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.)
@marktsuchida marktsuchida merged commit 9a35738 into micro-manager:main Apr 7, 2026
16 checks passed
@marktsuchida marktsuchida deleted the simplify-notification-queue-mutex branch April 7, 2026 20:29
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.

1 participant