Commit 20115391 authored by Kirill Smelkov's avatar Kirill Smelkov

bigfile/virtmem: Move _PyThreadState_Current_GET to compat_py2.h

_PyThreadState_Current_GET() is a function to get current python thread
state without asserting it is !NULL. It was added as part of d53271b9
(bigfile/virtmem: Big Virtmem lock)

We are going to adapt it to Python 3.5 (see next patch), so before doing
so move it to our compatibility place.

In the new place the name is _PyThreadState_UncheckedGet -- like such
function is named in Python 3.5 (again, see next patch).

Updates: nexedi/wendelin.core#1
parent 66379fe8
......@@ -777,16 +777,6 @@ static /*const*/ PyMethodDef pybigfile_modulemeths[] = {
/* GIL hooks for virtmem big lock */
static PyThreadState *_PyThreadState_Current_GET(void)
{
/* non-debug version of PyThreadState_GET() */
#if PY_MAJOR_VERSION < 3
return _PyThreadState_Current;
#else
return (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current);
#endif
}
static void *py_gil_ensure_unlocked(void)
{
/* make sure we don't hold python GIL (not to deadlock, as GIL oscillates)
......@@ -799,7 +789,7 @@ static void *py_gil_ensure_unlocked(void)
* NOTE2 we don't call PyThreadState_Get() as that thinks it is a bug when
* _PyThreadState_Current == NULL */
PyThreadState *ts_my = PyGILState_GetThisThreadState();
PyThreadState *ts_current = _PyThreadState_Current_GET();
PyThreadState *ts_current = _PyThreadState_UncheckedGet();
PyThreadState *ts;
if (ts_my && (ts_my == ts_current)) {
......
......@@ -51,4 +51,18 @@ typedef struct {
#endif
/* get current thread state without asserting it is !NULL
* (PyThreadState_Get() does the assert) */
#if PY_MAJOR_VERSION < 3
static inline PyThreadState * _PyThreadState_UncheckedGet(void)
{
return _PyThreadState_Current;
}
#else
static inline PyThreadState * _PyThreadState_UncheckedGet(void)
{
return (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current);
}
#endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment