Skip to content

Commit

Permalink
Add portable-atomic crate for the platforms where AtomicU64 is no…
Browse files Browse the repository at this point in the history
…t available
  • Loading branch information
tatsuya6502 committed Jan 4, 2025
1 parent e7fd7f6 commit 6628cf4
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
run: cargo test --release --lib --features sync sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored

- name: Run tests (future feature, but no sync feature)
run: cargo test --no-default-features --features 'future, atomic64, quanta'
run: cargo test --features future

- name: Run tests (future, sync and logging features)
run: cargo test --features 'future, sync, logging'
2 changes: 1 addition & 1 deletion .github/workflows/CIArm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
run: cargo test --release --lib --features sync sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored

- name: Run tests (future feature, but no sync feature)
run: cargo test --no-default-features --features 'future, atomic64, quanta'
run: cargo test --features future
env:
RUSTFLAGS: '--cfg skip_large_mem_tests'

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/CIQuantaDisabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ jobs:
run: ./.ci_extras/remove-examples-msrv.sh

- name: Run tests (debug, but no quanta feature)
run: cargo test --no-default-features --features 'sync, atomic64'
run: cargo test --no-default-features --features sync
env:
RUSTFLAGS: '--cfg rustver'

- name: Run tests (release, but no quanta feature)
run: cargo test --release --no-default-features --features 'sync, atomic64'
run: cargo test --release --no-default-features --features sync
env:
RUSTFLAGS: '--cfg rustver'

- name: Run tests (future feature, but no quanta and sync features)
run: cargo test --no-default-features --features 'future, atomic64'
run: cargo test --no-default-features --features future

- name: Run tests (future, sync and logging features, but no quanta feature)
run: cargo test --no-default-features --features 'sync, future, atomic64, logging'
run: cargo test --no-default-features --features 'sync, future, logging'

- name: Run tests (sync feature, but no quanta feature, drop cache)
run: cargo test --release --lib --no-default-features --features sync sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored
2 changes: 1 addition & 1 deletion .github/workflows/Codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
RUSTFLAGS: '--cfg rustver'

- name: Run tests (no quanta feature)
run: cargo llvm-cov --no-report --no-default-features --features 'sync, future, atomic64'
run: cargo llvm-cov --no-report --no-default-features --features 'sync, future'
env:
RUSTFLAGS: '--cfg rustver'

Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/LinuxCrossCompileTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@ jobs:
rust-version: stable
# Platforms without AtomicU64 support.
- target: armv5te-unknown-linux-musleabi
cargo-opts: "--no-default-features" # Disable atomic64 and quanta features.
rust-version: stable
- target: mips-unknown-linux-musl
cargo-opts: "--no-default-features" # Disable atomic64 and quanta features.
rust-version: "1.72.1"
cargo-version: "+1.72.1"
- target: mipsel-unknown-linux-musl
cargo-opts: "--no-default-features" # Disable atomic64 and quanta features.
rust-version: "1.72.1"
cargo-version: "+1.72.1"

Expand Down Expand Up @@ -86,17 +83,17 @@ jobs:
- name: Run tests (sync feature)
run: |
cross ${{ matrix.platform.carge-version }} test --release -F sync \
--target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}
--target ${{ matrix.platform.target }}
env:
RUSTFLAGS: '--cfg rustver'

- name: Run tests (future feature)
run: |
cross ${{ matrix.platform.cargo-version }} test --release -F future \
--target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}
--target ${{ matrix.platform.target }}
- name: Run tests (sync feature, drop cache)
run: |
cross ${{ matrix.platform.cargo-version }} test --release -F sync \
--target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }} \
--target ${{ matrix.platform.target }} \
--lib sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exclude = [".devcontainer", ".github", ".gitpod.yml", ".vscode"]
build = "build.rs"

[features]
default = ["atomic64", "quanta"]
default = ["quanta"]

# Enable this feature to use `moka::sync::{Cache, SegmentedCache}`
sync = []
Expand All @@ -29,9 +29,12 @@ future = ["async-lock", "event-listener", "futures-util"]
# callback closure.
logging = ["log"]

# This feature is enabled by default, but will be automatically disabled if the
# target platform does not support `std::sync::atomic::AtomicU64`.
# (e.g. `armv5te-unknown-linux-musleabi` or `mips-unknown-linux-musl`)
# This feature is enabled by default. It will slightly speed up some cache operations
# by using the `quanta` crate to measure time.
quanta = ["dep:quanta"]

# This is an old feature and has no effect in v0.12.10 or newer. It is kept for
# backward compatibility and will be removed in v0.13.0.
atomic64 = []

# This unstable feature adds `GlobalDebugCounters::current` function, which returns
Expand All @@ -44,6 +47,7 @@ crossbeam-channel = "0.5.5"
crossbeam-epoch = "0.9.9"
crossbeam-utils = "0.8"
parking_lot = "0.12"
portable-atomic = { version = "1.6", default-features = false }
smallvec = "1.8"
tagptr = "0.2"
thiserror = "1.0"
Expand Down
32 changes: 0 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ routers. Here are some highlights:
- [Size Aware Eviction](#example-size-aware-eviction)
- [Expiration Policies](#expiration-policies)
- [Minimum Supported Rust Versions](#minimum-supported-rust-versions)
- Troubleshooting
- [Compile Errors on Some 32-bit Platforms](#compile-errors-on-some-32-bit-platforms)
- [Developing Moka](#developing-moka)
- [Road Map](#road-map)
- [About the Name](#about-the-name)
Expand Down Expand Up @@ -483,36 +481,6 @@ In both cases, increasing MSRV is _not_ considered a semver-breaking change.
- quanta v0.12.4 requires 1.70.0.
-->


## Troubleshooting

### Compile Errors on Some 32-bit Platforms (Moka v0.12.8 or earlier)

On some 32-bit target platforms including the followings, you may encounter compile
errors if you use Moka v0.12.8 or earlier:

- `armv5te-unknown-linux-musleabi`
- `mips-unknown-linux-musl`
- `mipsel-unknown-linux-musl`

```console
error[E0432]: unresolved import `std::sync::atomic::AtomicU64`
--> ... /moka-0.5.3/src/sync.rs:10:30
|
10 | atomic::{AtomicBool, AtomicU64, Ordering},
| ^^^^^^^^^
| |
| no `AtomicU64` in `sync::atomic`
```

Such errors can occur because `std::sync::atomic::AtomicU64` is not provided on these
platforms but Moka uses it.

You can avoid the errors by upgrading Moka to v0.12.9 or later. These versions should
automatically disable the `atomic64` feature, which is one of the default features of
Moka. Disabling the feature will cause Moka to switch to a fall-back implementation,
so that it will compile.

## Developing Moka

**Running All Tests**
Expand Down
7 changes: 2 additions & 5 deletions src/common/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ pub(crate) mod entry_info;
#[cfg(feature = "sync")]
pub(crate) mod housekeeper;

#[cfg_attr(feature = "quanta", path = "concurrent/atomic_time/atomic_time.rs")]
#[cfg_attr(
all(feature = "atomic64", feature = "quanta", target_has_atomic = "64"),
path = "concurrent/atomic_time/atomic_time.rs"
)]
#[cfg_attr(
not(all(feature = "atomic64", feature = "quanta")),
not(feature = "quanta"),
path = "concurrent/atomic_time/atomic_time_compat.rs"
)]
pub(crate) mod atomic_time;
Expand Down
7 changes: 3 additions & 4 deletions src/common/concurrent/atomic_time/atomic_time.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::common::time::{clock::Instant as ClockInstant, Instant};

use std::{
any::TypeId,
sync::atomic::{AtomicU64, Ordering},
};
use std::{any::TypeId, sync::atomic::Ordering};

use portable_atomic::AtomicU64;

#[derive(Debug)]
pub(crate) struct AtomicInstant {
Expand Down

0 comments on commit 6628cf4

Please sign in to comment.