Skip to content

Commit

Permalink
change RefCell with AtomicCell
Browse files Browse the repository at this point in the history
Signed-off-by: glorv <glorvs@163.com>
  • Loading branch information
glorv committed Dec 16, 2022
1 parent c652691 commit dd767d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/tikv/yatp/"
[dependencies]
crossbeam-deque = "0.8"
crossbeam-skiplist = "0.1"
crossbeam-utils = "0.8"
dashmap = "5.1"
fail = "0.5"
lazy_static = "1"
Expand Down
11 changes: 4 additions & 7 deletions src/queue/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//! information.

use std::{
cell::RefCell,
sync::{
atomic::{AtomicU64, Ordering},
Arc,
Expand All @@ -18,6 +17,7 @@ use std::{
};

use crossbeam_skiplist::SkipMap;
use crossbeam_utils::atomic::AtomicCell;
use prometheus::local::LocalIntCounter;
use prometheus::IntCounter;

Expand Down Expand Up @@ -157,19 +157,16 @@ impl<T: TaskCell + Send + 'static> QueueCore<T> {
}
}

/// A holder to store task. Wrap the task in a RefCell becuase crossbeam-skip only provide
/// A holder to store task. Wrap the task in a AtomicCell becuase crossbeam-skip only provide
/// readonly acess to a popped Entry.
struct Slot<T> {
cell: RefCell<Option<T>>,
cell: AtomicCell<Option<T>>,
}

// It is safe here because the value is only visited by the thread which calls `pop()`.
unsafe impl<T: Send> Sync for Slot<T> {}

impl<T> Slot<T> {
fn new(value: T) -> Self {
Self {
cell: RefCell::new(Some(value)),
cell: AtomicCell::new(Some(value)),
}
}

Expand Down

0 comments on commit dd767d2

Please sign in to comment.