-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
sync: Implement Clone
for watch::Sender
#6388
Conversation
tokio/src/sync/watch.rs
Outdated
@@ -146,6 +146,16 @@ pub struct Sender<T> { | |||
shared: Arc<Shared<T>>, | |||
} | |||
|
|||
impl<T> Clone for Sender<T> { | |||
fn clone(&self) -> Self { | |||
self.shared.ref_count_tx.fetch_add(1, AcqRel); |
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.
When it comes to incrementing refcounts (but not decrementing), relaxed is generally enough.
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.
Fixed.
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.
Motivation
This PR attempt to resolve #4809.
Currently, watch channel has only one sender but this enable it to be mpmc by adding a
clone
of the sender.Solution
As with the reciever, the
ref_count_tx
field is added to the shared structure to record the number of senders; this counter is incremented by the sender'sclone
method and decremented by thedrop
method.