Skip to content

Commit

Permalink
use atomic::swap instead of atomic::fetch_update when cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian8j2 committed Sep 18, 2024
1 parent a40c338 commit e3dddff
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions forwarder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,8 @@ fn try_cleanup(peer_manager: &RwLock<PeerManager>) {
let mut peers = peer_manager.write();
let mut used_client_count = 0;
for peer in peers.get_all() {
let result = peer
.used
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |used| {
if used {
Some(false)
} else {
None
}
});
// `used` was false
if result.is_err() {
let used = peer.used.swap(false, Ordering::Relaxed);
if !used {
let client_addr = peer.get_client_addr();
log::info!("cleaning peer that handled '{client_addr}'");
peers.remove_peer(client_addr, peer.get_token());
Expand Down

0 comments on commit e3dddff

Please sign in to comment.