Skip to content

Commit

Permalink
Removing useless Atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Apr 26, 2024
1 parent 252c29a commit 2e63747
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions chitchat/src/listener.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::{BTreeMap, HashMap};
use std::ops::Bound;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, RwLock, Weak};

use tracing::error;
Expand Down Expand Up @@ -59,9 +58,8 @@ impl Listeners {
let key_prefix = key_prefix.to_string();
let weak_listeners = Arc::downgrade(&self.inner);
let mut inner_listener_guard = self.inner.write().unwrap();
let new_idx = inner_listener_guard
.listener_idx
.fetch_add(1, Ordering::Relaxed);
let new_idx = inner_listener_guard.listener_idx;
inner_listener_guard.listener_idx += 1;
let callback_entry = CallbackEntry {
prefix: key_prefix.clone(),
callback: boxed_listener,
Expand Down Expand Up @@ -93,7 +91,7 @@ struct InnerListeners {
// A trie would have been more efficient, but in reality we don't have
// that many listeners.
listeners: BTreeMap<String, Vec<CallbackId>>,
listener_idx: AtomicUsize,
listener_idx: usize,
// Callbacks is a hashmap because as we delete listeners, we create "holes" in the
// callback_id -> callback mapping
callbacks: HashMap<usize, CallbackEntry>,
Expand Down Expand Up @@ -171,6 +169,8 @@ impl InnerListeners {

#[cfg(test)]
mod tests {
use std::sync::atomic::{Ordering, AtomicUsize};

use super::*;
use crate::ChitchatId;

Expand Down

0 comments on commit 2e63747

Please sign in to comment.