Skip to content

Commit b340c76

Browse files
Merge #109
109: Update parking_lot to 0.11 r=matklad a=coolreader18 Co-authored-by: Noah <[email protected]>
2 parents 0b65b15 + a4cf20a commit b340c76

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exclude = ["*.png", "*.svg", "/Cargo.lock.min", "/.travis.yml", "/run-miri-tests
1919
# Uses parking_lot to implement once_cell::sync::OnceCell.
2020
# This makes not speed difference, but makes each OnceCell<T>
2121
# for up to two bytes smaller, depending on the size of the T.
22-
parking_lot = { version = "0.10.0", optional = true, default_features = false }
22+
parking_lot = { version = "0.11", optional = true, default_features = false }
2323

2424
[dev-dependencies]
2525
lazy_static = "1.0.0"

src/imp_pl.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::{
66
sync::atomic::{AtomicBool, Ordering},
77
};
88

9-
use parking_lot::{lock_api::RawMutex as _RawMutex, RawMutex};
9+
use parking_lot::Mutex;
1010

1111
pub(crate) struct OnceCell<T> {
12-
mutex: Mutex,
12+
mutex: Mutex<()>,
1313
is_initialized: AtomicBool,
1414
value: UnsafeCell<MaybeUninit<T>>,
1515
}
@@ -28,7 +28,7 @@ impl<T: UnwindSafe> UnwindSafe for OnceCell<T> {}
2828
impl<T> OnceCell<T> {
2929
pub(crate) const fn new() -> OnceCell<T> {
3030
OnceCell {
31-
mutex: Mutex::new(),
31+
mutex: parking_lot::const_mutex(()),
3232
is_initialized: AtomicBool::new(false),
3333
value: UnsafeCell::new(MaybeUninit::uninit()),
3434
}
@@ -130,32 +130,6 @@ impl<T> Drop for OnceCell<T> {
130130
}
131131
}
132132

133-
/// Wrapper around parking_lot's `RawMutex` which has `const fn` new.
134-
struct Mutex {
135-
inner: RawMutex,
136-
}
137-
138-
impl Mutex {
139-
const fn new() -> Mutex {
140-
Mutex { inner: RawMutex::INIT }
141-
}
142-
143-
fn lock(&self) -> MutexGuard<'_> {
144-
self.inner.lock();
145-
MutexGuard { inner: &self.inner }
146-
}
147-
}
148-
149-
struct MutexGuard<'a> {
150-
inner: &'a RawMutex,
151-
}
152-
153-
impl Drop for MutexGuard<'_> {
154-
fn drop(&mut self) {
155-
self.inner.unlock();
156-
}
157-
}
158-
159133
#[test]
160134
fn test_size() {
161135
use std::mem::size_of;

0 commit comments

Comments
 (0)