Skip to content

Commit

Permalink
fix(api)!: fix safety issue with raw::Mutex locking API (#17)
Browse files Browse the repository at this point in the history
* remove `raw::MutexGuard`
* remove `raw::Mutex::lock` and `raw::Mutex::try_lock`
* rename `raw::Mutex::lock_with` method to `raw::Mutex::lock_then`
* rename `raw::Mutex::try_lock_with` method to `raw::Mutex::try_lock_then`
* rename `raw::Mutex::lock_with_local` method to `raw::Mutex::lock_with_local_then`
* rename `raw::Mutex::lock_with_local_unchecked` method to `raw::Mutex::lock_with_local_then_unchecked`
* rename `raw::Mutex::try_lock_with_local` method to `raw::Mutex::try_lock_with_local_then`
* rename `raw::Mutex::try_lock_with_local_unchecked` method to `raw::Mutex::try_lock_with_local_then_unchecked`
* rename `barging::Mutex::lock_with` method to `barging::Mutex::lock_then`
* rename `barging::Mutex::try_lock_with` method to `barging::Mutex::try_lock_then`
* change closure parameters of `raw::Mutex`'s `then` (previous `with`) locking methods from `MutexGuard` to `&mut T`
* add new `raw::Mutex::lock_with_then` method
* add new `raw::Mutex::try_lock_with_then` method
  • Loading branch information
pedromfedricci authored Nov 2, 2024
1 parent ff456f5 commit 9622d92
Show file tree
Hide file tree
Showing 26 changed files with 2,951 additions and 1,807 deletions.
3 changes: 3 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[profile.default-miri]
test-threads = "num-cpus"
slow-timeout = { period = "120s", terminate-after = 2 }
31 changes: 25 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: rustup target add ${{ env.NO_STD_TARGET }}
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: Build with no_std compatible features
- name: Build on no_std environment
run: >
cargo hack build
--target ${{ env.NO_STD_TARGET }}
Expand All @@ -54,17 +54,18 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust 1.65.0
# NOTE: We actually installing the first nightly 1.66.0. It should be
# equivalent to stable 1.65.0. We need the nightly version to use the
# NOTE: We are actually installing the first nightly 1.66.0. It should
# be equivalent to stable 1.65.0. We need the nightly version to use the
# sparse registry feature. This massively improves the index download.
# Link: https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html
run: rustup toolchain install nightly-2022-09-18
- name: Set Rust 1.65.0 as default
run: rustup default nightly-2022-09-18
- name: Check MSRV
run: cargo check --all-features

docs:
name: Docs
docsrs:
name: Build doc
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -78,6 +79,17 @@ jobs:
RUSTDOCFLAGS: --cfg docsrs -D warnings
run: cargo doc --all-features

doc:
name: Test doc
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust stable
run: rustup toolchain install stable
- name: Run doc snippets
run: cargo test --doc --all-features

examples:
name: Examples
runs-on: ubuntu-latest
Expand Down Expand Up @@ -109,6 +121,10 @@ jobs:
env:
RUSTFLAGS: -D warnings -D clippy::pedantic -D clippy::nursery
run: cargo hack clippy --feature-powerset --no-dev-deps
- name: Lint test profile
env:
RUSTFLAGS: -D warnings -D clippy::pedantic -D clippy::nursery
run: cargo hack clippy --profile test --feature-powerset --no-dev-deps
- name: Lint loom
env:
RUSTFLAGS: --cfg loom -D warnings -D clippy::pedantic -D clippy::nursery
Expand Down Expand Up @@ -146,8 +162,11 @@ jobs:
run: rustup toolchain install nightly --component miri
- name: Set Rust nightly as default
run: rustup default nightly
# NOTE: Nextest is configure to run Miri against `num-cpus` threads.
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Miri test
run: cargo miri test --all-features
run: cargo miri nextest run --all-features

loom:
name: Loom
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/semver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Semver

on:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
semver:
name: Check semver
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust stable
run: rustup toolchain install stable
- name: Check semver violations
uses: obi1kenobi/cargo-semver-checks-action@v2
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
description = """
An implementation of Mellor-Crummey and Scott contention-free
spin-lock for mutual exclusion, referred to as MCS lock.
lock for mutual exclusion, referred to as MCS lock.
"""
name = "mcslock"
version = "0.3.0"
Expand All @@ -13,29 +13,32 @@ readme = "README.md"
documentation = "https://docs.rs/mcslock"
repository = "https://github.com/pedromfedricci/mcslock"
authors = ["Pedro de Matos Fedricci <pedromfedricci@gmail.com>"]
categories = ["no-std", "concurrency"]
keywords = ["no_std", "mutex", "spin-lock", "mcs-lock"]
categories = ["algorithms", "concurrency", "no-std", "no-std::no-alloc"]
keywords = ["mutex", "no_std", "spinlock", "synchronization"]

[features]
# NOTE: Features `yield` and `thread_local` require std.
# NOTE: Features `yield`, `thread_local` require std.
yield = []
thread_local = []
barging = []
# NOTE: The `dep:` syntax requires Rust 1.60.
lock_api = ["barging", "dep:lock_api"]
lock_api = ["dep:lock_api"]

[dependencies.lock_api]
version = "0.4"
default-features = false
optional = true

[target.'cfg(loom)'.dev-dependencies]
loom = { version = "0.7" }
[target.'cfg(loom)'.dev-dependencies.loom]
version = "0.7"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ["cfg(loom)", "cfg(tarpaulin)", "cfg(tarpaulin_include)"]

[[example]]
name = "barging"
required-features = ["barging"]
Expand Down
23 changes: 16 additions & 7 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ args = ["rustdoc", "--all-features", "--open", "--", "--default-theme", "ayu"]

# Check MSRV.
[tasks.msrv]
# NOTE: We actually installing the first nightly 1.66.0. It should be
# equivalent to stable 1.65.0. We need the nightly version to use the
# sparse registry feature. This massively improves the index download.
# NOTE: We are actually installing the first nightly 1.66.0. It should be
# equivalent to stable 1.65.0. We need the nightly version to use the sparse
# registry feature. This massively improves the index download.
# Link: https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html
toolchain = "nightly-2022-09-17"
toolchain = "nightly-2022-09-18"
command = "cargo"
env = { "CARGO_UNSTABLE_SPARSE_REGISTRY" = "true" }
# TODO: add `--all` for benches.
args = ["check", "--all-features"]

# Check semver viloations.
[tasks.semver]
command = "cargo"
args = ["semver-checks", "${@}"]

# Run all documentation snippets.
[tasks.doc-test]
command = "cargo"
args = ["test", "--doc", "--all-features"]

# Lint all feature combinations with cargo-hack.
[tasks.lint]
command = "cargo"
Expand All @@ -46,7 +55,7 @@ env = { "RUSTFLAGS" = "${CLIPPY_FLAGS}" }
args = ["run", "--example", "${@}", "--all-features"]

# Lint all feature combinations with carg-hack on test profile.
[tasks.lint-test]
[tasks.test-lint]
command = "cargo"
env = { "RUSTFLAGS" = "${CLIPPY_FLAGS}" }
args = ["hack", "clippy", "--profile", "test", "--feature-powerset",
Expand All @@ -58,7 +67,7 @@ args = ["hack", "clippy", "--profile", "test", "--feature-powerset",
toolchain = "nightly"
install_crate = { rustup_component_name = "miri" }
command = "cargo"
args = ["miri", "test", "--all-features", "${@}"]
args = ["miri", "nextest", "run", "--all-features", "${@}"]

# Check code coverage with tarpaulin (all features).
[tasks.tarpaulin]
Expand Down
Loading

0 comments on commit 9622d92

Please sign in to comment.