semka/
lib.rs

1//!Semaphore primitive for Rust
2//!
3//!## Platform implementation
4//!
5//!#### Windows
6//!
7//!Uses winapi `CreateSemaphoreW`.
8//!
9//!#### POSIX
10//!
11//!All POSIX-compliant systems uses `sem_init`
12//!But it must be noted that awaiting can be interrupted by the signal, although implementation
13//!tries its best to handle these cases
14//!
15//!POSIX implementation relies on [libc](https://github.com/rust-lang/libc)
16//!
17//!This includes all `unix` targets and `fuchsia`
18//!
19//!### Mac
20//!
21//!Uses `mach` API.
22
23#![no_std]
24#![warn(missing_docs)]
25#![cfg_attr(feature = "cargo-clippy", allow(clippy::style))]
26
27#[cold]
28#[inline(never)]
29fn unlikely<T>(result: T) -> T {
30    result
31}
32
33#[cfg(not(any(windows, unix, target_os = "fuchsia")))]
34compile_error!("Semaphore is not available for your target");
35
36#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios"))), target_os = "fuchsia"))]
37mod posix;
38#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios"))), target_os = "fuchsia"))]
39pub use posix::Sem;
40
41#[cfg(windows)]
42mod win32;
43#[cfg(windows)]
44pub use win32::Sem;
45
46#[cfg(any(target_os = "macos", target_os = "ios"))]
47mod mac;
48#[cfg(any(target_os = "macos", target_os = "ios"))]
49pub use mac::Sem;