-
-
Couldn't load subscription status.
- Fork 2.8k
sync: introduce NotifyGuard and refactor SetOnce to remove inner Mutex #7554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that eliminating the extra Mutex would improve both performance and code complexity.
it would be better for us to carefully consider how to achieve these benefits. The performance (including CPU and memory) penalty caused by the extra Mutex is not significant, which means that we should focus on reducing the code complexity.
The ideal case is that eliminating the extra Mutex and make people like me can understand the logic of critical code path in a few minutes.
Remove redundant pending check Co-authored-by: Alice Ryhl <aliceryhl@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR:
NotifyGuard, an internal type that wraps a lock onNotify’s waiter list and provides a method to wake all waiters while holding it.Mutex<()>fromSetOnceby having it re-use the mutex already owned by Notify, viaNotifyGuard.Motivation
The goal is to remove the extra mutex inside
SetOnceby having it reuseNotify's mutex. This avoids duplicate synchronisation and reduces memory footprint.Solution
SetOncenow acquires the lock throughNotify::lock, instead of holding its own mutex.