1//! Async synchronization primitives.
2//!
3//! This crate provides the following primitives:
4//!
5//! * [`Barrier`] - enables tasks to synchronize all together at the same time.
6//! * [`Mutex`] - a mutual exclusion lock.
7//! * [`RwLock`] - a reader-writer lock, allowing any number of readers or a single writer.
8//! * [`Semaphore`] - limits the number of concurrent operations.
9
10#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
11#![doc(
12 html_favicon_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
13)]
14#![doc(
15 html_logo_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
16)]
17
18/// Simple macro to extract the value of `Poll` or return `Pending`.
19///
20/// TODO: Drop in favor of `core::task::ready`, once MSRV is bumped to 1.64.
21macro_rules! ready {
22 ($e:expr) => {{
23 use ::core::task::Poll;
24
25 match $e {
26 Poll::Ready(v) => v,
27 Poll::Pending => return Poll::Pending,
28 }
29 }};
30}
31
32/// Pins a variable on the stack.
33///
34/// TODO: Drop in favor of `core::pin::pin`, once MSRV is bumped to 1.68.
35macro_rules! pin {
36 ($($x:ident),* $(,)?) => {
37 $(
38 let mut $x = $x;
39 #[allow(unused_mut)]
40 let mut $x = unsafe {
41 std::pin::Pin::new_unchecked(&mut $x)
42 };
43 )*
44 }
45}
46
47mod barrier;
48mod mutex;
49mod once_cell;
50mod rwlock;
51mod semaphore;
52
53pub use barrier::{Barrier, BarrierWaitResult};
54pub use mutex::{Mutex, MutexGuard, MutexGuardArc};
55pub use once_cell::OnceCell;
56pub use rwlock::{
57 RwLock, RwLockReadGuard, RwLockReadGuardArc, RwLockUpgradableReadGuard,
58 RwLockUpgradableReadGuardArc, RwLockWriteGuard, RwLockWriteGuardArc,
59};
60pub use semaphore::{Semaphore, SemaphoreGuard, SemaphoreGuardArc};
61
62pub mod futures {
63 //! Named futures for use with `async_lock` primitives.
64
65 pub use crate::barrier::BarrierWait;
66 pub use crate::mutex::{Lock, LockArc};
67 pub use crate::rwlock::futures::{
68 Read, ReadArc, UpgradableRead, UpgradableReadArc, Upgrade, UpgradeArc, Write, WriteArc,
69 };
70 pub use crate::semaphore::{Acquire, AcquireArc};
71}
72