-
-
Notifications
You must be signed in to change notification settings - Fork 76
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 #45 from moka-rs/merge-maint-0.5
Merge recent changes from maint-0.5 branch into master
- Loading branch information
Showing
19 changed files
with
329 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Linux cross compile tests | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '.devcontainer/**' | ||
- '.gitpod.yml' | ||
- '.vscode/**' | ||
- 'tests/**' | ||
pull_request: | ||
paths-ignore: | ||
- '.devcontainer/**' | ||
- '.gitpod.yml' | ||
- '.vscode/**' | ||
- 'tests/**' | ||
schedule: | ||
# Run against the last commit on the default branch on Friday at 9pm (UTC?) | ||
- cron: '0 21 * * 5' | ||
|
||
jobs: | ||
linux-cross: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
platform: | ||
- target: aarch64-unknown-linux-musl | ||
- target: i686-unknown-linux-musl | ||
- target: armv7-unknown-linux-musleabihf | ||
# Platforms without AtomicU64 support. | ||
- target: armv5te-unknown-linux-musleabi | ||
cargo-opts: "--no-default-features" # Disable atomic64 feature. | ||
- target: mips-unknown-linux-musl | ||
cargo-opts: "--no-default-features" # Disable atomic64 feature. | ||
- target: mipsel-unknown-linux-musl | ||
cargo-opts: "--no-default-features" # Disable atomic64 feature. | ||
|
||
steps: | ||
- name: Checkout Moka | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
target: ${{ matrix.platform.target }} | ||
override: true | ||
|
||
- name: Remove integration tests | ||
run: | | ||
rm -rf tests | ||
sed -i '/actix-rt\|async-std\|reqwest\|skeptic/d' Cargo.toml | ||
cat Cargo.toml | ||
- uses: Swatinem/rust-cache@v1 | ||
|
||
- name: cargo clean | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: clean | ||
|
||
- name: Run tests (no features) | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
use-cross: true | ||
command: test | ||
args: --release --target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }} | ||
|
||
- name: Run tests (future feature) | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
use-cross: true | ||
command: test | ||
args: --release --features future --target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }} |
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_atomic64.rs")] | ||
|
||
#[cfg_attr(feature = "atomic64", path = "common/time_atomic64.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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use parking_lot::RwLock; | ||
|
||
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: 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); | ||
} | ||
} |
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.