-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from moka-rs/mips-armv5
Support Linux on MIPS and ARMv5TE
- Loading branch information
Showing
18 changed files
with
323 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
use quanta::Instant; | ||
|
||
pub(crate) mod deque; | ||
pub(crate) mod error; | ||
pub(crate) mod frequency_sketch; | ||
pub(crate) mod thread_pool; | ||
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(feature = "atomic64", path = "common/time_quanta.rs")] | ||
#[cfg_attr(not(feature = "atomic64"), path = "common/time_compat.rs")] | ||
pub(crate) mod time; | ||
|
||
use time::Instant; | ||
|
||
pub(crate) trait AccessTime { | ||
fn last_accessed(&self) -> Option<Instant>; | ||
fn set_last_accessed(&mut self, timestamp: Instant); | ||
fn last_modified(&self) -> Option<Instant>; | ||
fn set_last_modified(&mut self, timestamp: Instant); | ||
} | ||
|
||
pub(crate) fn u64_to_instant(ts: u64) -> Option<Instant> { | ||
if ts == u64::MAX { | ||
None | ||
} else { | ||
Some(unsafe { std::mem::transmute(ts) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
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)) | ||
} | ||
} | ||
|
||
impl Ord for Instant { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
self.0.cmp(&other.0) | ||
} | ||
} | ||
|
||
pub(crate) struct AtomicInstant { | ||
instant: RwLock<Option<Instant>>, | ||
} | ||
|
||
impl Default for AtomicInstant { | ||
fn default() -> Self { | ||
Self { | ||
instant: RwLock::new(None), | ||
} | ||
} | ||
} | ||
|
||
impl AtomicInstant { | ||
pub(crate) fn reset(&self) { | ||
*self.instant.write() = None; | ||
} | ||
|
||
pub(crate) fn is_set(&self) -> bool { | ||
self.instant.read().is_some() | ||
} | ||
|
||
pub(crate) fn instant(&self) -> Option<Instant> { | ||
*self.instant.read() | ||
} | ||
|
||
pub(crate) fn set_instant(&self, instant: Instant) { | ||
*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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::sync::atomic::{AtomicU64, Ordering}; | ||
|
||
pub(crate) type Instant = quanta::Instant; | ||
pub(crate) type Clock = quanta::Clock; | ||
|
||
#[cfg(test)] | ||
pub(crate) type Mock = quanta::Mock; | ||
|
||
pub(crate) struct AtomicInstant { | ||
instant: AtomicU64, | ||
} | ||
|
||
impl Default for AtomicInstant { | ||
fn default() -> Self { | ||
Self { | ||
instant: AtomicU64::new(std::u64::MAX), | ||
} | ||
} | ||
} | ||
|
||
impl AtomicInstant { | ||
pub(crate) fn reset(&self) { | ||
self.instant.store(std::u64::MAX, Ordering::Release); | ||
} | ||
|
||
pub(crate) fn is_set(&self) -> bool { | ||
self.instant.load(Ordering::Acquire) != u64::MAX | ||
} | ||
|
||
pub(crate) fn instant(&self) -> Option<Instant> { | ||
let ts = self.instant.load(Ordering::Acquire); | ||
if ts == u64::MAX { | ||
None | ||
} else { | ||
Some(unsafe { std::mem::transmute(ts) }) | ||
} | ||
} | ||
|
||
pub(crate) fn set_instant(&self, instant: Instant) { | ||
self.instant.store(instant.as_u64(), Ordering::Release); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.