macro_rules! loom_const_fn {
($(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident : $ty:ty),* $(,)?) -> $ret:ty $body:block) => {
$(#[$attr])*
#[cfg(not(all(loom, test)))]
$vis const fn $name($($arg: $ty),*) -> $ret $body
$(#[$attr])*
#[cfg(all(loom, test))]
$vis fn $name($($arg: $ty),*) -> $ret $body
};
}
#[cfg(not(all(loom, test)))]
pub(crate) mod atomic_waker;
#[cfg(all(loom, test))]
#[doc(hidden)]
pub mod atomic_waker;
mod barrier;
pub mod broadcast;
mod cancellation;
mod contend;
mod event;
mod fair_semaphore;
pub(crate) mod internal;
mod latch;
mod lazy;
mod list;
#[cfg(all(loom, test))]
#[doc(hidden)]
pub(crate) mod loom_model;
#[cfg(all(test, loom))]
mod loom_tests;
pub mod mpsc;
mod mutex;
mod notify;
mod once_cell;
pub mod oneshot;
#[allow(dead_code)]
mod owned_lock;
mod owner;
mod queue;
mod raw_rwlock;
mod raw_semaphore;
mod reentrant_mutex;
mod reentrant_rwlock;
mod rwlock;
mod semaphore;
mod set_once;
mod spin;
#[cfg(all(test, not(loom)))]
pub(crate) mod test_support;
mod waiter;
pub mod watch;
pub use barrier::{Barrier, BarrierWait, BarrierWaitResult};
pub use cancellation::{
CancellationToken, DropGuard, DropGuardRef, WaitForCancellationFuture,
WaitForCancellationFutureOwned,
};
pub use contend::MAX_BYPASS;
pub use event::{Event, EventWait};
pub use latch::{Latch, LatchWait};
pub use lazy::Lazy;
pub use mutex::{
Lock, LockOwned, MappedMutexGuard, Mutex, MutexGuard, OwnedMappedMutexGuard, OwnedMutexGuard,
TryLockError,
};
pub use notify::{Notified, Notify, OwnedNotified};
pub use once_cell::{OnceCell, SetError};
#[cfg(test)]
#[allow(unused_imports)]
pub(crate) use owned_lock::between_take_and_grant;
pub use owner::{Owner, ThreadOwner};
pub use reentrant_mutex::{ReentrantMutex, ReentrantMutexGuard, ReentrantMutexLock};
pub use reentrant_rwlock::{
ReadHeldByOwner, ReentrantRead, ReentrantReadGuard, ReentrantRwLock, ReentrantWrite,
ReentrantWriteGuard,
};
pub use rwlock::{
OwnedRwLockMappedWriteGuard, OwnedRwLockReadGuard, OwnedRwLockWriteGuard, Read, ReadOwned,
RwLock, RwLockMappedWriteGuard, RwLockReadGuard, RwLockUpgradableReadGuard, RwLockWriteGuard,
UpgradableRead, Upgrade, Write, WriteOwned,
};
pub use semaphore::{
Acquire, AcquireError, AcquireOwned, OwnedSemaphorePermit, Semaphore, SemaphorePermit,
TryAcquireError,
};
pub use set_once::{SetOnce, SetOnceError};
pub mod futures {
pub use super::notify::{Notified, OwnedNotified};
}
pub use kovan::Atom;
pub use kovan_map::HopscotchMap;
pub use kovan_queue::array_queue::ArrayQueue;
pub use kovan_queue::seg_queue::{SegQueue, TryPopError};
#[cfg(all(test, not(loom)))]
mod tests {
use super::*;
fn send_sync<T: Send + Sync>() {}
fn future_is_send_sync<F: core::future::Future + Send + Sync>(_: &F) {}
#[test]
fn handles_futures_and_guards_are_send_and_sync() {
send_sync::<Mutex<u8>>();
send_sync::<Lock<'static, u8>>();
send_sync::<LockOwned<u8>>();
send_sync::<MutexGuard<'static, u8>>();
send_sync::<OwnedMutexGuard<u8>>();
send_sync::<MappedMutexGuard<'static, u8>>();
send_sync::<OwnedMappedMutexGuard<u8, u8>>();
send_sync::<RwLock<u8>>();
send_sync::<Read<'static, u8>>();
send_sync::<ReadOwned<u8>>();
send_sync::<Write<'static, u8>>();
send_sync::<RwLockReadGuard<'static, u8>>();
send_sync::<RwLockWriteGuard<'static, u8>>();
send_sync::<RwLockMappedWriteGuard<'static, u8>>();
send_sync::<WriteOwned<u8>>();
send_sync::<OwnedRwLockReadGuard<u8, u8>>();
send_sync::<OwnedRwLockWriteGuard<u8>>();
send_sync::<OwnedRwLockMappedWriteGuard<u8, u8>>();
send_sync::<RwLockUpgradableReadGuard<'static, u8>>();
send_sync::<UpgradableRead<'static, u8>>();
send_sync::<Upgrade<'static, u8>>();
send_sync::<ReadHeldByOwner>();
send_sync::<Semaphore>();
send_sync::<Acquire<'static>>();
send_sync::<AcquireOwned>();
send_sync::<SemaphorePermit<'static>>();
send_sync::<OwnedSemaphorePermit>();
send_sync::<Notify>();
send_sync::<Notified<'static>>();
send_sync::<OwnedNotified>();
send_sync::<TryLockError>();
send_sync::<AcquireError>();
send_sync::<TryAcquireError>();
send_sync::<SetError<u8>>();
send_sync::<SetOnceError<u8>>();
send_sync::<SetOnce<u8>>();
send_sync::<Event>();
send_sync::<EventWait<'static>>();
send_sync::<Latch>();
send_sync::<LatchWait<'static>>();
send_sync::<Barrier>();
send_sync::<BarrierWait<'static>>();
send_sync::<OnceCell<u8>>();
send_sync::<Lazy<u8>>();
send_sync::<ReentrantMutex<core::cell::RefCell<u8>>>();
send_sync::<ReentrantRwLock<u8>>();
send::<Owner>();
sync::<RwLockUpgradableReadGuard<'static, Option<std::sync::MutexGuard<'static, ()>>>>();
}
fn send<T: Send>() {}
fn sync<T: Sync>() {}
#[test]
fn async_entry_points_return_send_and_sync_futures() {
let cell = OnceCell::<u8>::new();
future_is_send_sync(&cell.get_or_init(|| async { 1 }));
future_is_send_sync(&cell.get_or_try_init(|| async { Ok::<u8, ()>(1) }));
let once = SetOnce::<u8>::new();
future_is_send_sync(&once.wait());
}
}