Skip to content

Commit

Permalink
bugfix: Use loom's thread_local when loom is enabled
Browse files Browse the repository at this point in the history
Using the std thread local can cause issues when using loom.

cc smol-rs/parking#23

Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull committed May 27, 2024
1 parent cd159e6 commit fdbe437
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ impl<T, B: Borrow<Inner<T>> + Unpin> InnerListener<T, B> {
(parker, Task::Unparker(unparker))
}

std::thread_local! {
crate::sync::thread_local! {
/// Cached thread-local parker/unparker pair.
static PARKER: (Parker, Task) = parker_and_task();
}
Expand Down Expand Up @@ -1371,6 +1371,8 @@ mod sync {

#[cfg(all(feature = "std", not(loom)))]
pub(super) use std::sync::{Mutex, MutexGuard};
#[cfg(all(feature = "std", not(target_family = "wasm"), not(loom)))]
pub(super) use std::thread_local;

pub(super) trait WithMut {
type Output;
Expand Down Expand Up @@ -1434,8 +1436,8 @@ mod sync {
#[cfg(loom)]
/// Synchronization primitive implementation.
mod sync {
pub(super) use loom::cell;
pub(super) use loom::sync::{atomic, Arc, Mutex, MutexGuard};
pub(super) use loom::{cell, thread_local};
}

fn __test_send_and_sync() {
Expand Down

0 comments on commit fdbe437

Please sign in to comment.