1
Fork 0

Use Mutex to avoid issue with conditional locks

This commit is contained in:
John Kåre Alsaker 2023-08-24 02:52:16 +02:00
parent 242805442b
commit d36393b839

View file

@ -41,6 +41,7 @@
//! [^2] `MTLockRef` is a typedef. //! [^2] `MTLockRef` is a typedef.
pub use crate::marker::*; pub use crate::marker::*;
use parking_lot::Mutex;
use std::any::Any; use std::any::Any;
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::{BuildHasher, Hash}; use std::hash::{BuildHasher, Hash};
@ -110,13 +111,13 @@ pub use mode::{is_dyn_thread_safe, set_dyn_thread_safe_mode};
/// continuing with unwinding. It's also used for the non-parallel code to ensure error message /// continuing with unwinding. It's also used for the non-parallel code to ensure error message
/// output match the parallel compiler for testing purposes. /// output match the parallel compiler for testing purposes.
pub struct ParallelGuard { pub struct ParallelGuard {
panic: Lock<Option<Box<dyn Any + std::marker::Send + 'static>>>, panic: Mutex<Option<Box<dyn Any + std::marker::Send + 'static>>>,
} }
impl ParallelGuard { impl ParallelGuard {
#[inline] #[inline]
pub fn new() -> Self { pub fn new() -> Self {
ParallelGuard { panic: Lock::new(None) } ParallelGuard { panic: Mutex::new(None) }
} }
pub fn run<R>(&self, f: impl FnOnce() -> R) -> Option<R> { pub fn run<R>(&self, f: impl FnOnce() -> R) -> Option<R> {
@ -316,8 +317,6 @@ cfg_if! {
} }
} }
} else { } else {
use parking_lot::Mutex;
pub use std::marker::Send as Send; pub use std::marker::Send as Send;
pub use std::marker::Sync as Sync; pub use std::marker::Sync as Sync;