forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-119344: Make critical section API public
- Loading branch information
Showing
10 changed files
with
184 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef Py_CPYTHON_CRITICAL_SECTION_H | ||
# error "this header file must not be included directly" | ||
#endif | ||
|
||
// Python critical sections. | ||
// | ||
// These operations are no-ops in the default build. See | ||
// pycore_critical_section.h for details. | ||
|
||
typedef struct _PyCriticalSection _PyCriticalSection; | ||
typedef struct _PyCriticalSection2 _PyCriticalSection2; | ||
|
||
#ifndef Py_GIL_DISABLED | ||
# define Py_BEGIN_CRITICAL_SECTION(op) \ | ||
{ | ||
# define Py_END_CRITICAL_SECTION() \ | ||
} | ||
# define Py_BEGIN_CRITICAL_SECTION2(a, b) \ | ||
{ | ||
# define Py_END_CRITICAL_SECTION2() \ | ||
} | ||
#else /* !Py_GIL_DISABLED */ | ||
|
||
// (private) | ||
struct _PyCriticalSection { | ||
// Tagged pointer to an outer active critical section (or 0). | ||
uintptr_t prev; | ||
|
||
// Mutex used to protect critical section | ||
struct _PyMutex *mutex; | ||
}; | ||
|
||
// (private) A critical section protected by two mutexes. Use | ||
// Py_BEGIN_CRITICAL_SECTION2 and Py_END_CRITICAL_SECTION2. | ||
struct _PyCriticalSection2 { | ||
struct _PyCriticalSection base; | ||
|
||
struct _PyMutex *mutex2; | ||
}; | ||
|
||
# define Py_BEGIN_CRITICAL_SECTION(op) \ | ||
{ \ | ||
_PyCriticalSection _cs; \ | ||
_PyCriticalSection_Begin(&_cs, _PyObject_CAST(op)) | ||
|
||
# define Py_END_CRITICAL_SECTION() \ | ||
_PyCriticalSection_End(&_cs); \ | ||
} | ||
|
||
# define Py_BEGIN_CRITICAL_SECTION2(a, b) \ | ||
{ \ | ||
_PyCriticalSection2 _cs2; \ | ||
_PyCriticalSection2_Begin(&_cs2, _PyObject_CAST(a), _PyObject_CAST(b)) | ||
|
||
# define Py_END_CRITICAL_SECTION2() \ | ||
_PyCriticalSection2_End(&_cs2); \ | ||
} | ||
|
||
#endif | ||
|
||
// (private) | ||
PyAPI_FUNC(void) | ||
_PyCriticalSection_Begin(_PyCriticalSection *c, PyObject *op); | ||
|
||
// (private) | ||
PyAPI_FUNC(void) | ||
_PyCriticalSection_End(_PyCriticalSection *c); | ||
|
||
// CPython internals should use pycore_critical_section.h instead. | ||
#ifdef Py_BUILD_CORE | ||
# undef Py_BEGIN_CRITICAL_SECTION | ||
# undef Py_END_CRITICAL_SECTION | ||
# undef Py_BEGIN_CRITICAL_SECTION2 | ||
# undef Py_END_CRITICAL_SECTION2 | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef Py_CRITICAL_SECTION_H | ||
#define Py_CRITICAL_SECTION_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_LIMITED_API | ||
# define Py_CPYTHON_CRITICAL_SECTION_H | ||
# include "cpython/critical_section.h" | ||
# undef Py_CPYTHON_CRITICAL_SECTION_H | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_CRITICAL_SECTION_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/C API/2024-05-21-19-41-41.gh-issue-119344.QKvzQb.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The critical section API is now public as part of the non-limited C API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.