Skip to main content

pyo3_ffi/impl_/
mod.rs

1#[cfg(all(Py_GIL_DISABLED, not(Py_LIMITED_API)))]
2mod atomic_c_ulong {
3    pub struct GetAtomicCULong<const WIDTH: usize>();
4
5    pub trait AtomicCULongType {
6        type Type;
7    }
8    impl AtomicCULongType for GetAtomicCULong<32> {
9        type Type = core::sync::atomic::AtomicU32;
10    }
11    impl AtomicCULongType for GetAtomicCULong<64> {
12        type Type = core::sync::atomic::AtomicU64;
13    }
14
15    pub type TYPE =
16        <GetAtomicCULong<{ core::mem::size_of::<core::ffi::c_ulong>() * 8 }> as AtomicCULongType>::Type;
17}
18
19/// Typedef for an atomic integer to match the platform-dependent c_ulong type.
20#[cfg(all(Py_GIL_DISABLED, not(Py_LIMITED_API)))]
21#[doc(hidden)]
22pub type AtomicCULong = atomic_c_ulong::TYPE;
23
24/// Guard to hang the current thread indefinitely when dropped.
25#[cfg(not(any(Py_3_14, target_arch = "wasm32")))]
26pub struct HangThread;
27
28#[cfg(not(any(Py_3_14, target_arch = "wasm32")))]
29impl Drop for HangThread {
30    fn drop(&mut self) {
31        loop {
32            std::thread::park(); // Block forever.
33        }
34    }
35}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here