Skip to content

Commit

Permalink
Relax atomic memory orderings
Browse files Browse the repository at this point in the history
  • Loading branch information
surban committed Dec 20, 2024
1 parent 9b1e2f9 commit 21871d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion remoc/src/chmux/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl Client {
}
}
Err(_) => {
if listener_dropped.load(Ordering::SeqCst) {
if listener_dropped.load(Ordering::Relaxed) {
Err(ConnectError::Rejected)
} else {
Err(ConnectError::ChMux)
Expand Down
14 changes: 7 additions & 7 deletions remoc/src/chmux/mux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ where
// Ensures that all ports are closed on both sides.
terminate &= self.ports.is_empty();
// Ensures that local clients are all dropped or remote listener is dropped.
terminate &= self.all_clients_dropped || self.remote_listener_dropped.load(Ordering::SeqCst);
terminate &= self.all_clients_dropped || self.remote_listener_dropped.load(Ordering::Relaxed);
// Ensures that local listener or all remote clients are dropped.
terminate &= self.listen_tx.is_none() || self.remote_client_dropped;
// No remote port requests are outstanding.
Expand Down Expand Up @@ -745,7 +745,7 @@ where
match event {
// Process local connect request.
GlobalEvt::ConnectReq(ConnectRequest { local_port, id, sent_tx: _sent_tx, response_tx, wait }) => {
if !self.remote_listener_dropped.load(Ordering::SeqCst) {
if !self.remote_listener_dropped.load(Ordering::Relaxed) {
let local_port_num = *local_port;
if self.ports.insert(local_port, PortState::Connecting { response_tx }).is_some() {
panic!("ConnectRequest for already used local port {local_port_num}");
Expand Down Expand Up @@ -1086,12 +1086,12 @@ where
..
}) = self.ports.get_mut(&port)
{
if !remote_receiver_closed.load(Ordering::SeqCst) {
if !remote_receiver_closed.load(Ordering::Relaxed) {
// Disable credits provider.
sender_credit_provider.close(true);

// Send hangup notifications.
remote_receiver_closed.store(true, Ordering::SeqCst);
remote_receiver_closed.store(true, Ordering::Relaxed);
let notifies = remote_receiver_closed_notify.xlock().unwrap().take().unwrap();
for tx in notifies {
let _ = tx.send(());
Expand Down Expand Up @@ -1122,12 +1122,12 @@ where
..
}) = self.ports.get_mut(&port)
{
if !remote_receiver_closed.load(Ordering::SeqCst) {
if !remote_receiver_closed.load(Ordering::Relaxed) {
// Disable credits provider.
sender_credit_provider.close(false);

// Send hangup notifications.
remote_receiver_closed.store(true, Ordering::SeqCst);
remote_receiver_closed.store(true, Ordering::Relaxed);
let notifies = remote_receiver_closed_notify.xlock().unwrap().take().unwrap();
for tx in notifies {
let _ = tx.send(());
Expand Down Expand Up @@ -1172,7 +1172,7 @@ where

// Remote endpoint will process no more connect requests.
MultiplexMsg::ListenerFinish => {
self.remote_listener_dropped.store(true, Ordering::SeqCst);
self.remote_listener_dropped.store(true, Ordering::Relaxed);
}

// Remote endpoint terminates connection.
Expand Down
2 changes: 1 addition & 1 deletion remoc/src/chmux/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl Sender {
/// True, once the remote endpoint has closed its receiver.
#[inline]
pub fn is_closed(&self) -> bool {
self.hangup_recved.upgrade().map(|hr| hr.load(Ordering::SeqCst)).unwrap_or_default()
self.hangup_recved.upgrade().map(|hr| hr.load(Ordering::Relaxed)).unwrap_or_default()
}

/// Returns a future that will resolve when the remote endpoint closes its receiver.
Expand Down

0 comments on commit 21871d6

Please sign in to comment.