Skip to content

Commit

Permalink
define public pyo3_ffi::PyMutex::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Sep 3, 2024
1 parent af80134 commit ff90dae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 10 additions & 1 deletion pyo3-ffi/src/cpython/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ pub struct PyMutex {
pub(crate) _pin: PhantomPinned,
}

impl PyMutex {
pub const fn new() -> PyMutex {
PyMutex {
_bits: AtomicU8::new(0),
_pin: PhantomPinned,
}
}
}

extern "C" {
pub fn PyMutex_Lock(m: *mut PyMutex);
pub fn PyMutex_UnLock(m: *mut PyMutex);
pub fn PyMutex_Unlock(m: *mut PyMutex);
}
9 changes: 2 additions & 7 deletions pyo3-ffi/src/object.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::pyport::{Py_hash_t, Py_ssize_t};
#[cfg(Py_GIL_DISABLED)]
use crate::PyMutex;
#[cfg(Py_GIL_DISABLED)]
use std::marker::PhantomPinned;
use std::mem;
use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void};
use std::ptr;
#[cfg(Py_GIL_DISABLED)]
use std::sync::atomic::{AtomicIsize, AtomicU32, AtomicU8, Ordering::Relaxed};
use std::sync::atomic::{AtomicIsize, AtomicU32, Ordering::Relaxed};

#[cfg(Py_LIMITED_API)]
opaque_struct!(PyTypeObject);
Expand Down Expand Up @@ -39,10 +37,7 @@ pub const PyObject_HEAD_INIT: PyObject = PyObject {
#[cfg(Py_GIL_DISABLED)]
_padding: 0,
#[cfg(Py_GIL_DISABLED)]
ob_mutex: PyMutex {
_bits: AtomicU8::new(0),
_pin: PhantomPinned,
},
ob_mutex: PyMutex::new(),
#[cfg(Py_GIL_DISABLED)]
ob_gc_bits: 0,
#[cfg(Py_GIL_DISABLED)]
Expand Down

0 comments on commit ff90dae

Please sign in to comment.