Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more intuitive portable-atomic feature etc. #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: [1.38.0]
version: [1.60.0]
steps:
- uses: actions/checkout@v3
- name: Install Rust
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- More intuitive `portable-atomic` option

### Changed

### Fixed

# [0.10.0] - (Pending)

### Added

### Changed

- Updated MSRV to 1.60
- Use `dep:` syntax in Cargo.toml

### Fixed

# [0.9.8] - 2023-04-03

### Fixed
Expand Down
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spin"
version = "0.9.8"
version = "0.10.0"
authors = [
"Mathijs van de Nes <git@mathijs.vd-nes.nl>",
"John Ericson <git@JohnEricson.me>",
Expand All @@ -10,7 +10,7 @@ license = "MIT"
repository = "https://github.com/mvdnes/spin-rs.git"
keywords = ["spinlock", "mutex", "rwlock"]
description = "Spin-based synchronization primitives"
rust-version = "1.38"
rust-version = "1.60"

[dependencies]
lock_api_crate = { package = "lock_api", version = "0.4", optional = true }
Expand Down Expand Up @@ -48,19 +48,20 @@ lazy = ["once"]
barrier = ["mutex"]

# Enables `lock_api`-compatible types that use the primitives in this crate internally.
lock_api = ["lock_api_crate"]
lock_api = ["dep:lock_api_crate"]

# Enables std-only features such as yield-relaxing.
std = []

# Use the portable_atomic crate to support platforms without native atomic operations.
# Use the `portable-atomic` crate to support platforms without native atomic operations.
# The `portable_atomic_unsafe_assume_single_core` cfg or `critical-section` feature
# of `portable-atomic` crate must also be set by the final binary crate.
# When using the cfg, note that it is unsafe and enabling it for multicore systems is unsound.
# When using the `critical-section` feature, you need to implement the critical-section
# implementation that sound for your system by implementing an unsafe trait.
# See the documentation for the `portable-atomic` crate for more information:
# https://docs.rs/portable-atomic/latest/portable_atomic/#optional-cfg
# See the documentation for the `portable-atomic` crate for more information
# with some requirements for no-std build:
# https://github.com/taiki-e/portable-atomic#optional-features
portable-atomic = ["dep:portable-atomic"]

# Deprecated alias:
portable_atomic = ["portable-atomic"]

[package.metadata.docs.rs]
Expand Down
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,13 @@ The crate comes with a few feature flags that you may wish to use.

- `std` enables support for thread yielding instead of spinning.

- `portable_atomic` enables usage of the `portable-atomic` crate
- `portable-atomic` enables usage of the `portable-atomic` crate
to support platforms without native atomic operations (Cortex-M0, etc.).
The `portable_atomic_unsafe_assume_single_core` cfg or `critical-section` feature
The `portable_atomic_unsafe_assume_single_core` or `critical-section` feature
of `portable-atomic` crate must also be set by the final binary crate.

When using the cfg, this can be done by adapting the following snippet to the `.cargo/config` file:
```
[target.<target>]
rustflags = [ "--cfg", "portable_atomic_unsafe_assume_single_core" ]
```
Note that this cfg is unsafe by nature, and enabling it for multicore systems is unsound.

When using the `critical-section` feature, you need to implement the critical-section
implementation that sound for your system by implementing an unsafe trait.
See [the documentation for the `portable-atomic` crate](https://docs.rs/portable-atomic/latest/portable_atomic/#optional-cfg)
for more information.
See the documentation for the `portable-atomic` crate for more information
with some requirements for no-std build:
https://github.com/taiki-e/portable-atomic#optional-features

## Remarks

Expand Down Expand Up @@ -135,7 +126,7 @@ spin = { version = "x.y", default-features = false, features = [...] }

## Minimum Safe Rust Version (MSRV)

This crate is guaranteed to compile on a Minimum Safe Rust Version (MSRV) of 1.38.0 and above.
This crate is guaranteed to compile on a Minimum Safe Rust Version (MSRV) of 1.60.0 and above.
This version will not be changed without a minor version bump.

## License
Expand Down
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,23 @@
//! starvation
//!
//! - `std` enables support for thread yielding instead of spinning
//!
//! - `portable-atomic` enables usage of the `portable-atomic` crate
//! to support platforms without native atomic operations (Cortex-M0, etc.).
//! See the documentation for the `portable-atomic` crate for more information
//! with some requirements for no-std build:
//! https://github.com/taiki-e/portable-atomic#optional-features


#[cfg(any(test, feature = "std"))]
extern crate core;

#[cfg(feature = "portable_atomic")]
#[cfg(feature = "portable-atomic")]
extern crate portable_atomic;

#[cfg(not(feature = "portable_atomic"))]
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic;
#[cfg(feature = "portable_atomic")]
#[cfg(feature = "portable-atomic")]
use portable_atomic as atomic;

#[cfg(feature = "barrier")]
Expand Down