Skip to content

Commit bf55381

Browse files
authored
Merge pull request #63 from rust-embedded/revert-loom
Revert "Add `loom` support to `std` critical section implementation"
2 parents d81c423 + 8b6fd1b commit bf55381

5 files changed

Lines changed: 5 additions & 75 deletions

File tree

.github/workflows/clippy.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ jobs:
1818
features: ''
1919
- rust: 1.63
2020
features: 'std'
21-
- rust: 1.73
22-
features: 'std'
23-
cfgs: "--cfg loom"
24-
2521
steps:
2622
- uses: actions/checkout@v2
2723
- name: Install Rust
@@ -31,4 +27,4 @@ jobs:
3127
components: clippy
3228
override: true
3329
- name: Clippy check
34-
run: RUSTFLAGS="${{matrix.cfgs}}" cargo clippy --features "${{matrix.features}}"
30+
run: cargo clippy --features "${{matrix.features}}"

.github/workflows/test.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ jobs:
1818
features: ''
1919
- rust: 1.63
2020
features: 'std'
21-
- rust: 1.73
22-
features: 'std'
23-
cfgs: "--cfg loom"
24-
# Lib tests are the only relevant & working ones
25-
# for loom.
26-
extra_flags: "--lib"
2721
steps:
2822
- uses: actions/checkout@v2
2923
- name: Install Rust
@@ -33,4 +27,4 @@ jobs:
3327
components: clippy
3428
override: true
3529
- name: Test
36-
run: RUSTFLAGS="${{matrix.cfgs}}" cargo test --features "${{matrix.features}}" ${{matrix.extra_flags}}
30+
run: cargo test --features "${{matrix.features}}"

Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,3 @@ restore-state-u16 = []
2929
restore-state-u32 = []
3030
restore-state-u64 = []
3131
restore-state-usize = []
32-
33-
[target.'cfg(loom)'.dependencies]
34-
loom = "0.7.2"
35-
36-
[lints.rust]
37-
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(loom)'] }

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ provide an implementation based on `std::sync::Mutex`, so you don't have to add
9999
critical-section = { version = "1.1", features = ["std"]}
100100
```
101101

102-
## Usage in [`loom`] tests
103-
104-
`critical-section` supports [`loom`] by enabling the `std` feature and passing `--cfg loom` as `RUSTFLAGS` (either through `.cargo/config.toml`, or through the environment variable).
105-
This implementation is identical to the normal `std` implementation, but uses `loom` synchronization primitives instead.
106-
107-
[`loom`]: https://docs.rs/loom/latest/loom/#writing-tests
108-
109102
## Usage in libraries
110103

111104
If you're writing a library intended to be portable across many targets, simply add a dependency on `critical-section`
@@ -226,7 +219,6 @@ This crate is guaranteed to compile on the following Rust versions:
226219

227220
- If the `std` feature is not enabled: stable Rust 1.54 and up.
228221
- If the `std` feature is enabled: stable Rust 1.63 and up.
229-
- If the `std` feature and `--cfg loom` are enabled: stable Rust 1.73 and up.
230222

231223
It might compile with older versions but that may change in any new patch release.
232224

src/std.rs

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
1+
use std::cell::Cell;
12
use std::mem::MaybeUninit;
3+
use std::sync::{Mutex, MutexGuard};
24

3-
#[cfg(not(loom))]
4-
use std::{
5-
cell::Cell,
6-
sync::{Mutex, MutexGuard},
7-
thread_local,
8-
};
9-
10-
#[cfg(loom)]
11-
use loom::{
12-
cell::Cell,
13-
sync::{Mutex, MutexGuard},
14-
thread_local,
15-
};
16-
17-
#[cfg(not(loom))]
185
static GLOBAL_MUTEX: Mutex<()> = Mutex::new(());
196

20-
#[cfg(loom)]
21-
loom::lazy_static! {
22-
static ref GLOBAL_MUTEX: Mutex<()> = Mutex::new(());
23-
}
24-
257
// This is initialized if a thread has acquired the CS, uninitialized otherwise.
268
static mut GLOBAL_GUARD: MaybeUninit<MutexGuard<'static, ()>> = MaybeUninit::uninit();
279

28-
thread_local!(static IS_LOCKED: Cell<bool> = Cell::new(false));
10+
std::thread_local!(static IS_LOCKED: Cell<bool> = Cell::new(false));
2911

3012
struct StdCriticalSection;
3113
crate::set_impl!(StdCriticalSection);
@@ -82,7 +64,6 @@ unsafe impl crate::Impl for StdCriticalSection {
8264
}
8365

8466
#[cfg(test)]
85-
#[cfg(not(loom))]
8667
mod tests {
8768
use std::thread;
8869

@@ -104,30 +85,3 @@ mod tests {
10485
})
10586
}
10687
}
107-
108-
#[cfg(test)]
109-
#[cfg(loom)]
110-
mod tests {
111-
use crate as critical_section;
112-
113-
#[cfg(feature = "std")]
114-
#[test]
115-
#[should_panic(expected = "Not a PoisonError!")]
116-
fn reusable_after_panic_loom() {
117-
loom::model(|| {
118-
// IMPORTANT: using `std::thread` here because `loom` is effectively
119-
// single-threaded, so panicking in `loom::thread` will panic the
120-
// entire test.
121-
let _ = std::thread::spawn(|| {
122-
critical_section::with(|_| {
123-
panic!("Boom!");
124-
});
125-
})
126-
.join();
127-
128-
critical_section::with(|_| {
129-
panic!("Not a PoisonError!");
130-
})
131-
})
132-
}
133-
}

0 commit comments

Comments
 (0)