From 6366f2494190dd9d9dced9a0af9bab8ffe8edcad Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Mon, 26 Jun 2023 17:36:43 +0000 Subject: [PATCH] wip --- .../runtime/scheduler/multi_thread/worker.rs | 3 - tokio/src/runtime/task/atomic_cell.rs | 99 ------------------- tokio/src/runtime/task/mod.rs | 3 - 3 files changed, 105 deletions(-) delete mode 100644 tokio/src/runtime/task/atomic_cell.rs diff --git a/tokio/src/runtime/scheduler/multi_thread/worker.rs b/tokio/src/runtime/scheduler/multi_thread/worker.rs index ba35ac5b3..cca3a19df 100644 --- a/tokio/src/runtime/scheduler/multi_thread/worker.rs +++ b/tokio/src/runtime/scheduler/multi_thread/worker.rs @@ -257,9 +257,6 @@ type Task = task::Task>; /// A notified task handle type Notified = task::Notified>; -/// Stealable LIFO slot -type Lifo = task::AtomicCell>; - /// Value picked out of thin-air. Running the LIFO slot a handful of times /// seemms sufficient to benefit from locality. More than 3 times probably is /// overweighing. The value can be tuned in the future with data that shows diff --git a/tokio/src/runtime/task/atomic_cell.rs b/tokio/src/runtime/task/atomic_cell.rs deleted file mode 100644 index 4ecfe108a..000000000 --- a/tokio/src/runtime/task/atomic_cell.rs +++ /dev/null @@ -1,99 +0,0 @@ -use crate::loom::sync::atomic::AtomicPtr; -use crate::loom::sync::atomic::Ordering::{AcqRel, Acquire, Release}; -use crate::runtime::task::{Header, Notified, RawTask}; - -use std::marker::PhantomData; -use std::ptr::{self, NonNull}; - -pub(crate) struct AtomicCell { - task: AtomicPtr
, - _p: PhantomData, -} - -impl AtomicCell { - pub(crate) fn new() -> AtomicCell { - AtomicCell { - task: AtomicPtr::default(), - _p: PhantomData, - } - } - - /// Should be called from a local context - pub(crate) fn is_some(&self) -> bool { - !self.is_none() - } - - pub(crate) fn is_none(&self) -> bool { - self.task.load(Acquire).is_null() - } - - pub(crate) fn take_local(&self) -> Option> { - let ptr = self.task.load(Acquire); - - if ptr.is_null() { - return None; - } - - if self - .task - .compare_exchange(ptr, ptr::null_mut(), AcqRel, Acquire) - .is_err() - { - return None; - } - - NonNull::new(ptr).map(|ptr| unsafe { Notified::from_raw(RawTask::from_raw(ptr)) }) - } - - pub(crate) fn swap_local(&self, task: Notified) -> Option> { - let next = task.into_raw().header_ptr().as_ptr(); - let prev = self.task.load(Acquire); - - if prev.is_null() { - // Since this method is only called from the only thread that can - // set the value to !null, it is safe to use a store here. - self.task.store(next, Release); - return None; - } - - if self - .task - .compare_exchange(prev, next, AcqRel, Acquire) - .is_ok() - { - // Safety: we already checked !null above - let prev = - unsafe { Notified::from_raw(RawTask::from_raw(NonNull::new_unchecked(prev))) }; - return Some(prev); - } - - // The compare-exchanged failed, but there is no need to try again since - // this is the only thread that could set the cell to !null. - self.task.store(next, Release); - None - } - - pub(crate) fn take_remote(&self) -> Option> { - let task = self.task.load(Acquire); - - if task.is_null() { - return None; - } - - // std::thread::sleep(std::time::Duration::from_micros(3)); - - // Try to take it once - if self - .task - .compare_exchange(task, ptr::null_mut(), Acquire, Acquire) - .is_ok() - { - // safety: we checked for null above - return Some(unsafe { - Notified::from_raw(RawTask::from_raw(NonNull::new_unchecked(task))) - }); - } - - None - } -} diff --git a/tokio/src/runtime/task/mod.rs b/tokio/src/runtime/task/mod.rs index e9fec729a..932552fb9 100644 --- a/tokio/src/runtime/task/mod.rs +++ b/tokio/src/runtime/task/mod.rs @@ -168,9 +168,6 @@ // unstable. This should be removed once `JoinSet` is stabilized. #![cfg_attr(not(tokio_unstable), allow(dead_code))] -mod atomic_cell; -pub(crate) use atomic_cell::AtomicCell; - mod core; use self::core::Cell; use self::core::Header;