Skip to content

Commit 5dbd7ab

Browse files
authored
Merge pull request #480 from moka-rs/portable-atomic
Add `portable-atomic` crate for the platforms where `AtomicU64` is not available
2 parents e7fd7f6 + dd17cc1 commit 5dbd7ab

File tree

11 files changed

+37
-61
lines changed

11 files changed

+37
-61
lines changed

.github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
run: cargo test --release --lib --features sync sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored
102102

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

106106
- name: Run tests (future, sync and logging features)
107107
run: cargo test --features 'future, sync, logging'

.github/workflows/CIArm64.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: cargo test --release --lib --features sync sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored
5757

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

.github/workflows/CIQuantaDisabled.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ jobs:
6868
run: ./.ci_extras/remove-examples-msrv.sh
6969

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

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

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

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

8686
- name: Run tests (sync feature, but no quanta feature, drop cache)
8787
run: cargo test --release --lib --no-default-features --features sync sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored

.github/workflows/Codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
RUSTFLAGS: '--cfg rustver'
3030

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

.github/workflows/LinuxCrossCompileTest.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ jobs:
4747
rust-version: stable
4848
# Platforms without AtomicU64 support.
4949
- target: armv5te-unknown-linux-musleabi
50-
cargo-opts: "--no-default-features" # Disable atomic64 and quanta features.
5150
rust-version: stable
5251
- target: mips-unknown-linux-musl
53-
cargo-opts: "--no-default-features" # Disable atomic64 and quanta features.
5452
rust-version: "1.72.1"
5553
cargo-version: "+1.72.1"
5654
- target: mipsel-unknown-linux-musl
57-
cargo-opts: "--no-default-features" # Disable atomic64 and quanta features.
5855
rust-version: "1.72.1"
5956
cargo-version: "+1.72.1"
6057

@@ -86,17 +83,17 @@ jobs:
8683
- name: Run tests (sync feature)
8784
run: |
8885
cross ${{ matrix.platform.carge-version }} test --release -F sync \
89-
--target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}
86+
--target ${{ matrix.platform.target }}
9087
env:
9188
RUSTFLAGS: '--cfg rustver'
9289

9390
- name: Run tests (future feature)
9491
run: |
9592
cross ${{ matrix.platform.cargo-version }} test --release -F future \
96-
--target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}
93+
--target ${{ matrix.platform.target }}
9794
9895
- name: Run tests (sync feature, drop cache)
9996
run: |
10097
cross ${{ matrix.platform.cargo-version }} test --release -F sync \
101-
--target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }} \
98+
--target ${{ matrix.platform.target }} \
10299
--lib sync::cache::tests::ensure_gc_runs_when_dropping_cache -- --exact --ignored

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Moka Cache — Change Log
22

3+
## Version 0.12.10
4+
5+
### Changed
6+
7+
- Switched to `AtomicU64` of `portable-atomic` crate for the platforms where
8+
`AtomicU64` is not available in `std`. ([#480][gh-pull-0480])
9+
- `moka`'s `atomic64` feature no longer has any effect on the build as
10+
`AtomicU64` is now always used. But the feature is kept for backward
11+
compatibility.
12+
13+
314
## Version 0.12.9
415

516
Bumped the minimum supported Rust version (MSRV) to 1.70 (June 1, 2023)
@@ -937,6 +948,7 @@ The minimum supported Rust version (MSRV) is now 1.51.0 (Mar 25, 2021).
937948
[gh-issue-0034]: https://github.com/moka-rs/moka/issues/34/
938949
[gh-issue-0031]: https://github.com/moka-rs/moka/issues/31/
939950

951+
[gh-pull-0480]: https://github.com/moka-rs/moka/pull/480/
940952
[gh-pull-0474]: https://github.com/moka-rs/moka/pull/474/
941953
[gh-pull-0466]: https://github.com/moka-rs/moka/pull/466/
942954
[gh-pull-0460]: https://github.com/moka-rs/moka/pull/460/

Cargo.toml

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "moka"
3-
version = "0.12.9"
3+
version = "0.12.10"
44
edition = "2021"
55
# Rust 1.70 was released on June 1, 2023.
66
rust-version = "1.70"
@@ -16,7 +16,7 @@ exclude = [".devcontainer", ".github", ".gitpod.yml", ".vscode"]
1616
build = "build.rs"
1717

1818
[features]
19-
default = ["atomic64", "quanta"]
19+
default = ["quanta"]
2020

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

32-
# This feature is enabled by default, but will be automatically disabled if the
33-
# target platform does not support `std::sync::atomic::AtomicU64`.
34-
# (e.g. `armv5te-unknown-linux-musleabi` or `mips-unknown-linux-musl`)
32+
# This feature is enabled by default. It will slightly speed up some cache operations
33+
# by using the `quanta` crate to measure time.
34+
quanta = ["dep:quanta"]
35+
36+
# This is an old feature and has no effect in v0.12.10 or newer. It is kept for
37+
# backward compatibility and will be removed in v0.13.0.
3538
atomic64 = []
3639

3740
# This unstable feature adds `GlobalDebugCounters::current` function, which returns
@@ -44,6 +47,7 @@ crossbeam-channel = "0.5.5"
4447
crossbeam-epoch = "0.9.9"
4548
crossbeam-utils = "0.8"
4649
parking_lot = "0.12"
50+
portable-atomic = "1.6"
4751
smallvec = "1.8"
4852
tagptr = "0.2"
4953
thiserror = "1.0"

README.md

-32
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ routers. Here are some highlights:
143143
- [Size Aware Eviction](#example-size-aware-eviction)
144144
- [Expiration Policies](#expiration-policies)
145145
- [Minimum Supported Rust Versions](#minimum-supported-rust-versions)
146-
- Troubleshooting
147-
- [Compile Errors on Some 32-bit Platforms](#compile-errors-on-some-32-bit-platforms)
148146
- [Developing Moka](#developing-moka)
149147
- [Road Map](#road-map)
150148
- [About the Name](#about-the-name)
@@ -483,36 +481,6 @@ In both cases, increasing MSRV is _not_ considered a semver-breaking change.
483481
- quanta v0.12.4 requires 1.70.0.
484482
-->
485483

486-
487-
## Troubleshooting
488-
489-
### Compile Errors on Some 32-bit Platforms (Moka v0.12.8 or earlier)
490-
491-
On some 32-bit target platforms including the followings, you may encounter compile
492-
errors if you use Moka v0.12.8 or earlier:
493-
494-
- `armv5te-unknown-linux-musleabi`
495-
- `mips-unknown-linux-musl`
496-
- `mipsel-unknown-linux-musl`
497-
498-
```console
499-
error[E0432]: unresolved import `std::sync::atomic::AtomicU64`
500-
--> ... /moka-0.5.3/src/sync.rs:10:30
501-
|
502-
10 | atomic::{AtomicBool, AtomicU64, Ordering},
503-
| ^^^^^^^^^
504-
| |
505-
| no `AtomicU64` in `sync::atomic`
506-
```
507-
508-
Such errors can occur because `std::sync::atomic::AtomicU64` is not provided on these
509-
platforms but Moka uses it.
510-
511-
You can avoid the errors by upgrading Moka to v0.12.9 or later. These versions should
512-
automatically disable the `atomic64` feature, which is one of the default features of
513-
Moka. Disabling the feature will cause Moka to switch to a fall-back implementation,
514-
so that it will compile.
515-
516484
## Developing Moka
517485

518486
**Running All Tests**

src/common/concurrent.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ pub(crate) mod entry_info;
1212
#[cfg(feature = "sync")]
1313
pub(crate) mod housekeeper;
1414

15+
#[cfg_attr(feature = "quanta", path = "concurrent/atomic_time/atomic_time.rs")]
1516
#[cfg_attr(
16-
all(feature = "atomic64", feature = "quanta", target_has_atomic = "64"),
17-
path = "concurrent/atomic_time/atomic_time.rs"
18-
)]
19-
#[cfg_attr(
20-
not(all(feature = "atomic64", feature = "quanta")),
17+
not(feature = "quanta"),
2118
path = "concurrent/atomic_time/atomic_time_compat.rs"
2219
)]
2320
pub(crate) mod atomic_time;

src/common/concurrent/atomic_time/atomic_time.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::common::time::{clock::Instant as ClockInstant, Instant};
22

3-
use std::{
4-
any::TypeId,
5-
sync::atomic::{AtomicU64, Ordering},
6-
};
3+
use std::{any::TypeId, sync::atomic::Ordering};
4+
5+
use portable_atomic::AtomicU64;
76

87
#[derive(Debug)]
98
pub(crate) struct AtomicInstant {

src/common/concurrent/entry_info.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,8 @@ mod test {
215215
};
216216

217217
let expected_sizes = match (arch, is_quanta_enabled) {
218-
(Linux64 | Linux32Arm, true) => vec![("1.51", 56)],
218+
(Linux64 | Linux32Arm | Linux32Mips, true) => vec![("1.51", 56)],
219219
(Linux32X86, true) => vec![("1.51", 48)],
220-
(Linux32Mips, true) => unimplemented!(),
221220
(MacOS64, true) => vec![("1.62", 56)],
222221
(Linux64, false) => vec![("1.66", 104), ("1.60", 128)],
223222
(Linux32X86, false) => unimplemented!(),

0 commit comments

Comments
 (0)