Skip to main content

pyo3_ffi/
critical_section.rs

1#[cfg(any(
2    all(Py_GIL_DISABLED, Py_3_13, not(Py_LIMITED_API)),
3    all(Py_3_15, not(Py_LIMITED_API))
4))]
5use crate::PyMutex;
6#[cfg(any(all(Py_GIL_DISABLED, Py_3_13), Py_3_15))]
7use crate::PyObject;
8
9#[cfg(all(Py_LIMITED_API, Py_3_13))]
10opaque_struct!(pub PyMutex);
11
12#[cfg(any(all(Py_GIL_DISABLED, Py_3_13, not(Py_LIMITED_API)), Py_3_15,))]
13#[repr(C)]
14pub struct PyCriticalSection {
15    _cs_prev: usize,
16    _cs_mutex: *mut PyMutex,
17}
18
19#[cfg(any(all(Py_GIL_DISABLED, Py_3_13, not(Py_LIMITED_API)), Py_3_15,))]
20#[repr(C)]
21pub struct PyCriticalSection2 {
22    _cs_base: PyCriticalSection,
23    _cs_mutex2: *mut PyMutex,
24}
25
26#[cfg(all(not(Py_GIL_DISABLED), Py_3_13, not(Py_3_15), not(Py_LIMITED_API)))]
27opaque_struct!(pub PyCriticalSection);
28#[cfg(all(not(Py_GIL_DISABLED), Py_3_13, not(Py_3_15), not(Py_LIMITED_API)))]
29opaque_struct!(pub PyCriticalSection2);
30
31#[cfg(any(all(Py_GIL_DISABLED, Py_3_13), Py_3_15))]
32extern_libpython! {
33    pub fn PyCriticalSection_Begin(c: *mut PyCriticalSection, op: *mut PyObject);
34    pub fn PyCriticalSection_End(c: *mut PyCriticalSection);
35    pub fn PyCriticalSection2_Begin(c: *mut PyCriticalSection2, a: *mut PyObject, b: *mut PyObject);
36    pub fn PyCriticalSection2_End(c: *mut PyCriticalSection2);
37}