1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Single-threaded async synchronization primitives.
//!
//! The types in this module coordinate futures that stay on one runite runtime
//! thread. They are intentionally `!Send`/`!Sync` and use thread-local wakeups
//! rather than cross-thread atomics.
//! They do not provide cross-thread fairness or synchronization: use channels,
//! [`crate::ThreadHandle`], or [`crate::WorkerHandle`] to coordinate between
//! runtime threads.
//!
//! Use [`Mutex`] for exclusive access to shared task-local state, [`RwLock`] for
//! shared-or-exclusive access, [`Semaphore`] for limiting concurrent access,
//! [`Notify`] for one-shot task wakeups, and [`OnceCell`] for asynchronous
//! initialize-once values.
//!
//! # Examples
//!
//! ```
//! use std::cell::Cell;
//! use std::rc::Rc;
//!
//! let mutex = Rc::new(runite::sync::Mutex::new(0));
//! let observed = Rc::new(Cell::new(0));
//!
//! runite::spawn({
//! let mutex = Rc::clone(&mutex);
//! let observed = Rc::clone(&observed);
//! async move {
//! let mut value = mutex.lock().await;
//! *value = 42;
//! observed.set(*value);
//! }
//! });
//!
//! runite::run();
//!
//! assert_eq!(observed.get(), 42);
//! ```
//!
//! `Notify` is useful for local one-shot wakeups:
//!
//! ```
//! use std::cell::Cell;
//! use std::rc::Rc;
//!
//! let notify = Rc::new(runite::sync::Notify::new());
//! let woke = Rc::new(Cell::new(false));
//!
//! runite::spawn({
//! let notify = Rc::clone(¬ify);
//! let woke = Rc::clone(&woke);
//! async move {
//! notify.notified().await;
//! woke.set(true);
//! }
//! });
//!
//! runite::queue_macrotask({
//! let notify = Rc::clone(¬ify);
//! move || notify.notify_one()
//! });
//!
//! runite::run();
//! assert!(woke.get());
//! ```
pub use ;
pub use Notify;
pub use OnceCell;
pub use ;
pub use ;