diff --git a/Cargo.lock b/Cargo.lock index e757159..5ce2912 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,12 +8,30 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "critical-section" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + [[package]] name = "lock_api" version = "0.4.12" @@ -31,14 +49,117 @@ dependencies = [ "critical-section", "lock_api", "mutex-traits", + "parking_lot", ] [[package]] name = "mutex-traits" version = "0.999.0" +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "redox_syscall" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +dependencies = [ + "bitflags", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/source/mutex/Cargo.toml b/source/mutex/Cargo.toml index 03bdeef..767efae 100644 --- a/source/mutex/Cargo.toml +++ b/source/mutex/Cargo.toml @@ -28,9 +28,14 @@ optional = true [dependencies.lock_api-0_4] package = "lock_api" version = "0.4" -default_features = false +default-features = false optional = true +[dependencies.parking_lot] +version = "0.12.3" +optional = true +default-features = false + [features] default = [ "impl-critical-section", @@ -42,4 +47,6 @@ impl-lock_api-0_4 = ["dep:lock_api-0_4"] # # These can be disabled when minimizing binary size is important. fmt = [] -std = [] +std = [ + "dep:parking_lot", +] diff --git a/source/mutex/src/raw_impls.rs b/source/mutex/src/raw_impls.rs index 2a8787d..b776b4c 100644 --- a/source/mutex/src/raw_impls.rs +++ b/source/mutex/src/raw_impls.rs @@ -269,3 +269,55 @@ pub mod lock_api_0_4 { } } } + +#[cfg(feature = "std")] +pub mod std { + //! Std implementation of the [RawMutex] trait + //! + //! Currently based on [`parking_lot::RawMutex], but subject to change + + use mutex_traits::{ConstInit, RawMutex}; + use parking_lot::{lock_api::RawMutex as _, RawMutex as PLRawMutex}; + + /// Std implementation of the [RawMutex] trait + /// + /// Currently based on [`parking_lot::RawMutex], but subject to change + #[cfg_attr(feature = "fmt", derive(Debug))] + pub struct StdRawMutex { + inner: PLRawMutex, + } + + impl ConstInit for StdRawMutex { + const INIT: Self = StdRawMutex { + inner: PLRawMutex::INIT, + }; + } + + unsafe impl RawMutex for StdRawMutex { + type GuardMarker = ::GuardMarker; + + #[inline] + #[track_caller] + fn lock(&self) { + self.inner.lock(); + } + + #[inline] + #[track_caller] + fn try_lock(&self) -> bool { + self.inner.try_lock() + } + + #[inline] + #[track_caller] + unsafe fn unlock(&self) { + self.inner.unlock() + } + + #[inline] + #[track_caller] + fn is_locked(&self) -> bool { + self.inner.is_locked() + } + } +}