Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bindings for critical section API #4477

Merged
merged 4 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/4477.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Added bindings for the Python critical section API available on Python 3.13 and newer.
30 changes: 30 additions & 0 deletions pyo3-ffi/src/cpython/critical_section.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#[cfg(Py_GIL_DISABLED)]
use crate::PyMutex;
use crate::PyObject;

#[repr(C)]
#[cfg(Py_GIL_DISABLED)]
pub struct PyCriticalSection {
_cs_prev: usize,
_cs_mutex: *mut PyMutex,
}

#[repr(C)]
#[cfg(Py_GIL_DISABLED)]
pub struct PyCriticalSection2 {
_cs_base: PyCriticalSection,
_cs_mutex2: *mut PyMutex,
}

#[cfg(not(Py_GIL_DISABLED))]
opaque_struct!(PyCriticalSection);

#[cfg(not(Py_GIL_DISABLED))]
opaque_struct!(PyCriticalSection2);

extern "C" {
pub fn PyCriticalSection_Begin(c: *mut PyCriticalSection, op: *mut PyObject);
pub fn PyCriticalSection_End(c: *mut PyCriticalSection);
pub fn PyCriticalSection2_Begin(c: *mut PyCriticalSection2, a: *mut PyObject, b: *mut PyObject);
pub fn PyCriticalSection2_End(c: *mut PyCriticalSection2);
}
4 changes: 4 additions & 0 deletions pyo3-ffi/src/cpython/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub(crate) mod bytesobject;
pub(crate) mod ceval;
pub(crate) mod code;
pub(crate) mod compile;
#[cfg(Py_3_13)]
pub(crate) mod critical_section;
pub(crate) mod descrobject;
#[cfg(not(PyPy))]
pub(crate) mod dictobject;
Expand Down Expand Up @@ -45,6 +47,8 @@ pub use self::bytesobject::*;
pub use self::ceval::*;
pub use self::code::*;
pub use self::compile::*;
#[cfg(Py_3_13)]
pub use self::critical_section::*;
pub use self::descrobject::*;
#[cfg(not(PyPy))]
pub use self::dictobject::*;
Expand Down
Loading