Skip to content
Merged
Changes from 4 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
11 changes: 11 additions & 0 deletions include/pybind11/detail/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,24 @@ class pymutex {
void unlock() { PyMutex_Unlock(&mutex); }
};

# if !(defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x030E00C1 /* 3.14.0rc1 */)
// Forward declaration of internal slow path function for usage in pycritical_section
void _PyCriticalSection_BeginSlow(PyCriticalSection *c, PyMutex *m);
# endif

class pycritical_section {
pymutex &mutex;
PyCriticalSection cs;

public:
explicit pycritical_section(pymutex &m) : mutex(m) {
// PyCriticalSection_BeginMutex was added in Python 3.15.0a1 and backported to 3.14.0rc1
# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x030E00C1 /* 3.14.0rc1 */
PyCriticalSection_BeginMutex(&cs, &mutex.mutex);
# else
// Use the slow path of internal API `_PyCriticalSection_BeginMutex` for older versions
_PyCriticalSection_BeginSlow(&cs, &mutex.mutex);
# endif
}
~pycritical_section() { PyCriticalSection_End(&cs); }

Expand Down
Loading