mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
timer: use std::sync::atomic::AtomicU64 instead of own AtomicU64 (#1421)
This commit is contained in:
@@ -1,88 +0,0 @@
|
|||||||
//! Implementation of an atomic u64 cell. On 64 bit platforms, this is a wrapper
|
|
||||||
//! around `AtomicUsize`. On 32 bit platforms, this is implemented using a
|
|
||||||
//! `Mutex`.
|
|
||||||
//!
|
|
||||||
//! This file can be removed if/when `AtomicU64` lands in `std`.
|
|
||||||
|
|
||||||
pub use self::imp::AtomicU64;
|
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
|
||||||
mod imp {
|
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AtomicU64 {
|
|
||||||
inner: AtomicUsize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AtomicU64 {
|
|
||||||
pub fn new(val: u64) -> AtomicU64 {
|
|
||||||
AtomicU64 {
|
|
||||||
inner: AtomicUsize::new(val as usize),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load(&self, ordering: Ordering) -> u64 {
|
|
||||||
self.inner.load(ordering) as u64
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn store(&self, val: u64, ordering: Ordering) {
|
|
||||||
self.inner.store(val as usize, ordering)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fetch_or(&self, val: u64, ordering: Ordering) -> u64 {
|
|
||||||
self.inner.fetch_or(val as usize, ordering) as u64
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compare_and_swap(&self, old: u64, new: u64, ordering: Ordering) -> u64 {
|
|
||||||
self.inner
|
|
||||||
.compare_and_swap(old as usize, new as usize, ordering) as u64
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_pointer_width = "64"))]
|
|
||||||
mod imp {
|
|
||||||
use std::sync::atomic::Ordering;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AtomicU64 {
|
|
||||||
inner: Mutex<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AtomicU64 {
|
|
||||||
pub fn new(val: u64) -> AtomicU64 {
|
|
||||||
AtomicU64 {
|
|
||||||
inner: Mutex::new(val),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load(&self, _: Ordering) -> u64 {
|
|
||||||
*self.inner.lock().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn store(&self, val: u64, _: Ordering) {
|
|
||||||
*self.inner.lock().unwrap() = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fetch_or(&self, val: u64, _: Ordering) -> u64 {
|
|
||||||
let mut lock = self.inner.lock().unwrap();
|
|
||||||
let prev = *lock;
|
|
||||||
*lock = prev | val;
|
|
||||||
prev
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compare_and_swap(&self, old: u64, new: u64, _: Ordering) -> u64 {
|
|
||||||
let mut lock = self.inner.lock().unwrap();
|
|
||||||
let prev = *lock;
|
|
||||||
|
|
||||||
if prev != old {
|
|
||||||
return prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
*lock = new;
|
|
||||||
prev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,6 @@ pub mod throttle;
|
|||||||
pub mod timeout;
|
pub mod timeout;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
|
|
||||||
mod atomic;
|
|
||||||
mod delay;
|
mod delay;
|
||||||
mod error;
|
mod error;
|
||||||
mod interval;
|
mod interval;
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use crate::atomic::AtomicU64;
|
|
||||||
use crate::timer::{HandlePriv, Inner};
|
use crate::timer::{HandlePriv, Inner};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crossbeam_utils::CachePadded;
|
use crossbeam_utils::CachePadded;
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::atomic::AtomicBool;
|
|
||||||
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
|
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
|
||||||
|
use std::sync::atomic::{AtomicBool, AtomicU64};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::task::{self, Poll};
|
use std::task::{self, Poll};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|||||||
@@ -49,11 +49,10 @@ pub use self::handle::{with_default, Handle};
|
|||||||
pub use self::now::{Now, SystemNow};
|
pub use self::now::{Now, SystemNow};
|
||||||
pub(crate) use self::registration::Registration;
|
pub(crate) use self::registration::Registration;
|
||||||
|
|
||||||
use crate::atomic::AtomicU64;
|
|
||||||
use crate::wheel;
|
use crate::wheel;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use std::sync::atomic::AtomicUsize;
|
|
||||||
use std::sync::atomic::Ordering::SeqCst;
|
use std::sync::atomic::Ordering::SeqCst;
|
||||||
|
use std::sync::atomic::{AtomicU64, AtomicUsize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use std::usize;
|
use std::usize;
|
||||||
|
|||||||
Reference in New Issue
Block a user