wgpu_sync/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(
3    clippy::ptr_as_ptr,
4    missing_docs,
5    unsafe_op_in_unsafe_fn,
6    unused_qualifications
7)]
8#![no_std]
9
10//! Provides [`Mutex`] and [`RwLock`] types with an appropriate implementation.
11
12extern crate alloc;
13#[cfg(feature = "std")]
14extern crate std;
15
16pub mod atomic;
17mod mutex;
18mod rwlock;
19
20pub use mutex::RawMutex;
21pub use rwlock::RawRwLock;
22
23cfg_if::cfg_if! {
24    if #[cfg(target_has_atomic = "ptr")] {
25        pub use alloc::sync::{Arc, Weak};
26    } else if #[cfg(feature = "portable-atomic")] {
27        pub use portable_atomic_util::{Arc, Weak};
28    }
29}
30
31// FIXME:
32// * `Condvar` is only available through `parking_lot` and not through `lock_api`.
33// * `Condvar` only works with the specific `RawMutex` implementation from `parking_lot`.
34#[cfg(feature = "std")]
35pub use parking_lot::{Condvar, Mutex as CondvarMutex};
36
37pub use once_cell::race::{OnceBool, OnceBox, OnceNonZeroUsize, OnceRef};
38
39cfg_if::cfg_if! {
40    if #[cfg(feature = "std")] {
41        pub use once_cell::sync::{Lazy, OnceCell};
42    } else {
43        pub use once_cell::unsync::{Lazy, OnceCell};
44    }
45}
46
47/// A [`Mutex`](lock_api::Mutex) using [`RawMutex`] for its backing implementation.
48pub type Mutex<T> = lock_api::Mutex<RawMutex, T>;
49
50/// A [`MutexGuard`](lock_api::MutexGuard) using [`RawMutex`] for its backing implementation.
51pub type MutexGuard<'a, T> = lock_api::MutexGuard<'a, RawMutex, T>;
52
53/// A [`MappedMutexGuard`](lock_api::MappedMutexGuard) using [`RawMutex`] for its backing implementation.
54pub type MappedMutexGuard<'a, T> = lock_api::MappedMutexGuard<'a, RawMutex, T>;
55
56/// A [`RwLock`](lock_api::RwLock) using [`RawRwLock`] for its backing implementation.
57pub type RwLock<T> = lock_api::RwLock<RawRwLock, T>;
58
59/// A [`RwLockReadGuard`](lock_api::RwLockReadGuard) using [`RawRwLock`] for its backing implementation.
60pub type RwLockReadGuard<'a, T> = lock_api::RwLockReadGuard<'a, RawRwLock, T>;
61
62/// A [`RwLockWriteGuard`](lock_api::RwLockWriteGuard) using [`RawRwLock`] for its backing implementation.
63pub type RwLockWriteGuard<'a, T> = lock_api::RwLockWriteGuard<'a, RawRwLock, T>;
64
65/// A [`RwLockUpgradableReadGuard`](lock_api::RwLockUpgradableReadGuard) using [`RawRwLock`] for its backing implementation.
66pub type RwLockUpgradableReadGuard<'a, T> = lock_api::RwLockUpgradableReadGuard<'a, RawRwLock, T>;