diff options
author | Haibo Huang <hhb@google.com> | 2021-02-09 18:18:56 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2021-03-03 21:34:52 +0000 |
commit | e3d8d80d2d8744ccdcd175323e0864c8f30fcedc (patch) | |
tree | 16d053e70d21e456d52f4a7762ee41441342b7a2 /src/time/driver/entry.rs | |
parent | 925d648e545e70d6a4faae3d7efe5e0de885f922 (diff) | |
download | tokio-e3d8d80d2d8744ccdcd175323e0864c8f30fcedc.tar.gz |
Upgrade rust/crates/tokio to 1.2.0
Test: make
Change-Id: Ib0f6a5201b51e9d122b6e867388a3856e16f803a
Diffstat (limited to 'src/time/driver/entry.rs')
-rw-r--r-- | src/time/driver/entry.rs | 76 |
1 files changed, 2 insertions, 74 deletions
diff --git a/src/time/driver/entry.rs b/src/time/driver/entry.rs index bcad988..11366d2 100644 --- a/src/time/driver/entry.rs +++ b/src/time/driver/entry.rs @@ -53,6 +53,7 @@ //! refuse to mark the timer as pending. use crate::loom::cell::UnsafeCell; +use crate::loom::sync::atomic::AtomicU64; use crate::loom::sync::atomic::Ordering; use crate::sync::AtomicWaker; @@ -71,79 +72,6 @@ const STATE_DEREGISTERED: u64 = u64::max_value(); const STATE_PENDING_FIRE: u64 = STATE_DEREGISTERED - 1; const STATE_MIN_VALUE: u64 = STATE_PENDING_FIRE; -/// Not all platforms support 64-bit compare-and-swap. This hack replaces the -/// AtomicU64 with a mutex around a u64 on platforms that don't. This is slow, -/// unfortunately, but 32-bit platforms are a bit niche so it'll do for now. -/// -/// Note: We use "x86 or 64-bit pointers" as the condition here because -/// target_has_atomic is not stable. -#[cfg(all( - not(tokio_force_time_entry_locked), - any(target_arch = "x86", target_pointer_width = "64") -))] -type AtomicU64 = crate::loom::sync::atomic::AtomicU64; - -#[cfg(not(all( - not(tokio_force_time_entry_locked), - any(target_arch = "x86", target_pointer_width = "64") -)))] -#[derive(Debug)] -struct AtomicU64 { - inner: crate::loom::sync::Mutex<u64>, -} - -#[cfg(not(all( - not(tokio_force_time_entry_locked), - any(target_arch = "x86", target_pointer_width = "64") -)))] -impl AtomicU64 { - fn new(v: u64) -> Self { - Self { - inner: crate::loom::sync::Mutex::new(v), - } - } - - fn load(&self, _order: Ordering) -> u64 { - debug_assert_ne!(_order, Ordering::SeqCst); // we only provide AcqRel with the lock - *self.inner.lock() - } - - fn store(&self, v: u64, _order: Ordering) { - debug_assert_ne!(_order, Ordering::SeqCst); // we only provide AcqRel with the lock - *self.inner.lock() = v; - } - - fn compare_exchange( - &self, - current: u64, - new: u64, - _success: Ordering, - _failure: Ordering, - ) -> Result<u64, u64> { - debug_assert_ne!(_success, Ordering::SeqCst); // we only provide AcqRel with the lock - debug_assert_ne!(_failure, Ordering::SeqCst); - - let mut lock = self.inner.lock(); - - if *lock == current { - *lock = new; - Ok(current) - } else { - Err(*lock) - } - } - - fn compare_exchange_weak( - &self, - current: u64, - new: u64, - success: Ordering, - failure: Ordering, - ) -> Result<u64, u64> { - self.compare_exchange(current, new, success, failure) - } -} - /// This structure holds the current shared state of the timer - its scheduled /// time (if registered), or otherwise the result of the timer completing, as /// well as the registered waker. @@ -300,7 +228,7 @@ impl StateCell { /// expiration time. /// /// While this function is memory-safe, it should only be called from a - /// context holding both `&mut TimerEntry` and the driver lock. + /// context holding both `&mut TimerEntry` and the driver lock. fn set_expiration(&self, timestamp: u64) { debug_assert!(timestamp < STATE_MIN_VALUE); |