Skip to content

Commit

Permalink
Restore quanta on 32-bit MIPS and ARMv5TE
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Sep 16, 2021
1 parent 988e5a8 commit 1074082
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ future = ["async-io", "async-lock"]
# support `std::sync::atomic::AtomicU64`. (e.g. `armv5te-unknown-linux-musleabi`
# or `mips-unknown-linux-musl`)
# https://github.com/moka-rs/moka#resolving-compile-errors-on-some-32-bit-platforms
atomic64 = ["quanta"]
atomic64 = []

[dependencies]
crossbeam-channel = "0.5"
Expand All @@ -44,7 +44,7 @@ uuid = { version = "0.8", features = ["v4"] }
# Optional dependencies
async-io = { version = "1.4", optional = true }
async-lock = { version = "2.4", optional = true }
quanta = { version = "0.9", optional = true }
quanta = "0.9.3"

[dev-dependencies]
actix-rt2 = { package = "actix-rt", version = "2", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub(crate) mod unsafe_weak_pointer;

// targe_has_atomic is more convenient but yet unstable (Rust 1.55)
// https://github.com/rust-lang/rust/issues/32976
// #[cfg_attr(target_has_atomic = "64", path = "common/time_quanta.rs")]
// #[cfg_attr(target_has_atomic = "64", path = "common/time_atomic64.rs")]

#[cfg_attr(feature = "atomic64", path = "common/time_quanta.rs")]
#[cfg_attr(feature = "atomic64", path = "common/time_atomic64.rs")]
#[cfg_attr(not(feature = "atomic64"), path = "common/time_compat.rs")]
pub(crate) mod time;

Expand Down
File renamed without changes.
76 changes: 4 additions & 72 deletions src/common/time_compat.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
use std::{
cmp::Ordering,
ops::Add,
sync::Arc,
time::{Duration, Instant as StdInstant},
};

use parking_lot::RwLock;

#[derive(Clone, Copy, PartialEq, Eq)]
pub(crate) struct Instant(StdInstant);

impl Instant {
pub(crate) fn now() -> Self {
Self(StdInstant::now())
}
}

impl Add<Duration> for Instant {
type Output = Instant;

fn add(self, other: Duration) -> Self::Output {
let instant = self
.0
.checked_add(other)
.expect("overflow when adding duration to instant");
Self(instant)
}
}

impl PartialOrd for Instant {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
pub(crate) type Instant = quanta::Instant;
pub(crate) type Clock = quanta::Clock;

impl Ord for Instant {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}
#[cfg(test)]
pub(crate) type Mock = quanta::Mock;

pub(crate) struct AtomicInstant {
instant: RwLock<Option<Instant>>,
Expand Down Expand Up @@ -69,37 +35,3 @@ impl AtomicInstant {
*self.instant.write() = Some(instant);
}
}

pub(crate) struct Clock(Arc<Mock>);

impl Clock {
#[cfg(test)]
pub(crate) fn mock() -> (Clock, Arc<Mock>) {
let mock = Arc::new(Mock::default());
let clock = Clock(Arc::clone(&mock));
(clock, mock)
}

pub(crate) fn now(&self) -> Instant {
Instant(*self.0.now.read())
}
}

pub(crate) struct Mock {
now: RwLock<StdInstant>,
}

impl Default for Mock {
fn default() -> Self {
Self {
now: RwLock::new(StdInstant::now()),
}
}
}

#[cfg(test)]
impl Mock {
pub(crate) fn increment(&self, amount: Duration) {
*self.now.write() += amount;
}
}

0 comments on commit 1074082

Please sign in to comment.