forked from compio-rs/synchrony
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
101 lines (92 loc) · 2.51 KB
/
lib.rs
File metadata and controls
101 lines (92 loc) · 2.51 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! A library that provides both sync and unsync versions of common
//! synchronization primitives.
//!
//! # Example
//!
//! If you're a library author, a common pattern is to provide a feature gate
//! that let users to choose whether they want multithread or not:
//!
//! ```toml
//! # cargo.toml
//! [dependencies]
//! synchrony = { version = "0.1.0", feature = ["mutex"] }
//!
//! [features]
//! sync_foo = []
//! ```
//!
//! and in your code:
//!
//! ```ignore
//! #[cfg(feature = "sync_foo")]
//! use synchrony::sync;
//! #[cfg(not(feature = "sync_foo"))]
//! use synchrony::unsync as sync;
//!
//! struct Foo {
//! lock: sync::mutex::Mutex,
//! count: sync::atomic::AtomicUsize,
//! }
//! ```
//!
//! Or you can also hand-pick sync/unsync primitives:
//!
//! ```ignore
//! use synchrony::*;
//!
//! let unsync_lock = unsync::bilock::BiLock::new(42);
//! let sync_counter = sync::atomic::AtomicUsize::new(42);
//! ```
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)]
#[cfg(feature = "mutex")]
mod mutex;
#[cfg(feature = "waker_slot")]
mod waker_slot;
#[cfg(feature = "event")]
mod event;
mod atomic;
mod bilock;
mod flag;
mod mutex_blocking;
mod shared;
/// Multithreaded version of primitives
pub mod sync {
/// Multithreaded `Watch` channel based on [`see`].
#[doc(inline)]
#[cfg(feature = "watch")]
pub use see::sync as watch;
#[doc(inline)]
#[cfg(feature = "mutex")]
pub use crate::mutex::sync as mutex;
#[doc(inline)]
#[cfg(feature = "waker_slot")]
pub use crate::waker_slot::sync as waker_slot;
#[doc(inline)]
pub use crate::{
atomic::sync as atomic, bilock::sync as bilock, event::sync as event, flag::sync as flag,
mutex_blocking::sync as mutex_blocking, shared::sync as shared,
};
}
/// Singlethreaded version of primitives
pub mod unsync {
/// Singlethreaded `Watch` channel based on [`see`].
#[doc(inline)]
#[cfg(feature = "watch")]
pub use see::unsync as watch;
#[doc(inline)]
#[cfg(feature = "mutex")]
pub use crate::mutex::unsync as mutex;
#[doc(inline)]
#[cfg(feature = "waker_slot")]
pub use crate::waker_slot::unsync as waker_slot;
#[doc(inline)]
pub use crate::{
atomic::unsync as atomic, bilock::unsync as bilock, event::unsync as event,
flag::unsync as flag, mutex_blocking::unsync as mutex_blocking, shared::unsync as shared,
};
}
/// A trait to assert that a type is `Send + Sync`.
#[allow(dead_code)]
trait AssertMt: Send + Sync {}