Skip to content

Commit fe8d029

Browse files
committed
bb8: Make parking_lot an optional feature enabled by default
1 parent 5737736 commit fe8d029

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

bb8/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ rust-version = "1.57"
1313
async-trait = "0.1"
1414
futures-channel = "0.3.2"
1515
futures-util = { version = "0.3.2", default-features = false, features = ["channel"] }
16-
parking_lot = "0.12"
17-
tokio = { version = "1.0", features = ["rt", "time", "parking_lot"] }
16+
parking_lot = { version = "0.12", optional = true }
17+
tokio = { version = "1.0", features = ["rt", "time"] }
1818

1919
[dev-dependencies]
2020
tokio = { version = "1.0", features = ["macros"] }
21+
22+
[features]
23+
parking-lot = ["parking_lot", "tokio/parking_lot"]
24+
default = ["parking-lot"]

bb8/src/internals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::cmp::min;
22
use std::sync::Arc;
33
use std::time::Instant;
44

5+
use crate::lock::Mutex;
56
use futures_channel::oneshot;
6-
use parking_lot::Mutex;
77

88
use crate::api::{Builder, ManageConnection};
99
use std::collections::VecDeque;

bb8/src/lib.rs

+30
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,33 @@ pub use api::{
4141

4242
mod inner;
4343
mod internals;
44+
mod lock {
45+
#[cfg(feature = "parking_lot")]
46+
use parking_lot::Mutex as MutexImpl;
47+
#[cfg(feature = "parking_lot")]
48+
use parking_lot::MutexGuard;
49+
50+
#[cfg(not(feature = "parking_lot"))]
51+
use std::sync::Mutex as MutexImpl;
52+
#[cfg(not(feature = "parking_lot"))]
53+
use std::sync::MutexGuard;
54+
55+
pub(crate) struct Mutex<T>(MutexImpl<T>);
56+
57+
impl<T> Mutex<T> {
58+
pub(crate) fn new(val: T) -> Self {
59+
Self(MutexImpl::new(val))
60+
}
61+
62+
pub(crate) fn lock(&self) -> MutexGuard<'_, T> {
63+
#[cfg(feature = "parking_lot")]
64+
{
65+
self.0.lock()
66+
}
67+
#[cfg(not(feature = "parking_lot"))]
68+
{
69+
self.0.lock().unwrap()
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)