abi_stable/external_types/
parking_lot.rs

1//! Ffi-safe synchronization primitives,most of which are ffi-safe wrappers of
2//! [parking_lot](https://crates.io/crates/parking_lot) types
3
4pub mod mutex;
5pub mod once;
6pub mod rw_lock;
7
8pub use self::{mutex::RMutex, once::ROnce, rw_lock::RRwLock};
9
10/////////////////////////////////////////////////////////////////////////////////
11
12use std::mem;
13
14use crate::StableAbi;
15
16#[cfg_attr(target_pointer_width = "128", repr(C, align(16)))]
17#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
18#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
19#[cfg_attr(target_pointer_width = "16", repr(C, align(2)))]
20#[derive(Copy, Clone, StableAbi)]
21struct Overaligner;
22
23const RAW_LOCK_SIZE: usize = mem::size_of::<usize>();
24
25#[repr(C)]
26#[derive(Copy, Clone, StableAbi)]
27#[sabi(unsafe_unconstrained(T))]
28struct UnsafeOveralignedField<T, P> {
29    #[sabi(unsafe_opaque_field)]
30    value: T,
31    /// Manual padding to ensure that the bytes are copied,
32    /// even if Rust thinks there is nothing in the padding.
33    _padding: P,
34    _alignment: Overaligner,
35}
36
37impl<T, P> UnsafeOveralignedField<T, P> {
38    const fn new(value: T, _padding: P) -> Self {
39        Self {
40            value,
41            _padding,
42            _alignment: Overaligner,
43        }
44    }
45}
46
47/////////////////////////////////////////////////////////////////////////////////