Commit 91f2ad9f authored by Stefan Behnel's avatar Stefan Behnel

use slightly faster thread state access where we know that we own the GIL

parent 90fa8d7c
...@@ -70,7 +70,7 @@ static int __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o) { ...@@ -70,7 +70,7 @@ static int __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o) {
o->ag_hooks_inited = 1; o->ag_hooks_inited = 1;
#if 0 #if 0
tstate = PyThreadState_GET(); tstate = __Pyx_PyThreadState_Current;
finalizer = tstate->async_gen_finalizer; finalizer = tstate->async_gen_finalizer;
if (finalizer) { if (finalizer) {
...@@ -209,7 +209,7 @@ __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o) ...@@ -209,7 +209,7 @@ __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o)
o->ag_hooks_inited = 1; o->ag_hooks_inited = 1;
tstate = PyThreadState_GET(); tstate = __Pyx_PyThreadState_Current;
finalizer = tstate->async_gen_finalizer; finalizer = tstate->async_gen_finalizer;
if (finalizer) { if (finalizer) {
......
...@@ -290,7 +290,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject ...@@ -290,7 +290,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
PyErr_Restore(tmp_type, tmp_value, tb); PyErr_Restore(tmp_type, tmp_value, tb);
Py_XDECREF(tmp_tb); Py_XDECREF(tmp_tb);
#else #else
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = __Pyx_PyThreadState_Current;
PyObject* tmp_tb = tstate->curexc_traceback; PyObject* tmp_tb = tstate->curexc_traceback;
if (tb != tmp_tb) { if (tb != tmp_tb) {
Py_INCREF(tb); Py_INCREF(tb);
...@@ -684,7 +684,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, ...@@ -684,7 +684,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
$global_code_object_cache_insert(c_line ? -c_line : py_line, py_code); $global_code_object_cache_insert(c_line ? -c_line : py_line, py_code);
} }
py_frame = PyFrame_New( py_frame = PyFrame_New(
PyThreadState_GET(), /*PyThreadState *tstate,*/ __Pyx_PyThreadState_Current, /*PyThreadState *tstate,*/
py_code, /*PyCodeObject *code,*/ py_code, /*PyCodeObject *code,*/
$moddict_cname, /*PyObject *globals,*/ $moddict_cname, /*PyObject *globals,*/
0 /*PyObject *locals*/ 0 /*PyObject *locals*/
......
...@@ -234,6 +234,16 @@ ...@@ -234,6 +234,16 @@
#define __Pyx_PyFastCFunction_Check(func) 0 #define __Pyx_PyFastCFunction_Check(func) 0
#endif #endif
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
#define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03050000
#define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
#define __Pyx_PyThreadState_Current PyThreadState_Get()
#else
#define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
/* new Py3.3 unicode type (PEP 393) */ /* new Py3.3 unicode type (PEP 393) */
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
#define CYTHON_PEP393_ENABLED 1 #define CYTHON_PEP393_ENABLED 1
...@@ -1128,17 +1138,10 @@ static void __Pyx_FastGilFuncInit(void); ...@@ -1128,17 +1138,10 @@ static void __Pyx_FastGilFuncInit(void);
#define __Pyx_FastGIL_PyCapsule \ #define __Pyx_FastGIL_PyCapsule \
__Pyx_FastGIL_ABI_module "." __Pyx_FastGIL_PyCapsuleName __Pyx_FastGIL_ABI_module "." __Pyx_FastGIL_PyCapsuleName
#if PY_VERSION_HEX >= 0x03050000 #if PY_VERSION_HEX < 0x02070000
#define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
#define __Pyx_PyThreadState_Current PyThreadState_Get()
#elif PY_VERSION_HEX < 0x02070000
#undef CYTHON_THREAD_LOCAL #undef CYTHON_THREAD_LOCAL
#else
#define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif #endif
#ifdef CYTHON_THREAD_LOCAL #ifdef CYTHON_THREAD_LOCAL
#include "pythread.h" #include "pythread.h"
......
...@@ -190,7 +190,7 @@ static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ ...@@ -190,7 +190,7 @@ static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/
static CYTHON_INLINE int __Pyx_IterFinish(void) { static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE #if CYTHON_FAST_THREAD_STATE
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = __Pyx_PyThreadState_Current;
PyObject* exc_type = tstate->curexc_type; PyObject* exc_type = tstate->curexc_type;
if (unlikely(exc_type)) { if (unlikely(exc_type)) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
...@@ -1495,7 +1495,7 @@ static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, ...@@ -1495,7 +1495,7 @@ static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args,
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
PyObject *globals) { PyObject *globals) {
PyFrameObject *f; PyFrameObject *f;
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = __Pyx_PyThreadState_Current;
PyObject **fastlocals; PyObject **fastlocals;
Py_ssize_t i; Py_ssize_t i;
PyObject *result; PyObject *result;
......
...@@ -60,10 +60,10 @@ ...@@ -60,10 +60,10 @@
if (CYTHON_TRACE_NOGIL) { \ if (CYTHON_TRACE_NOGIL) { \
PyThreadState *tstate; \ PyThreadState *tstate; \
PyGILState_STATE state = PyGILState_Ensure(); \ PyGILState_STATE state = PyGILState_Ensure(); \
tstate = PyThreadState_GET(); \ tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing) && !tstate->tracing && \ if (unlikely(tstate->use_tracing) && !tstate->tracing && \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
} \ } \
PyGILState_Release(state); \ PyGILState_Release(state); \
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing) && !tstate->tracing && \ if (unlikely(tstate->use_tracing) && !tstate->tracing && \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
} \ } \
} }
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
{ PyThreadState* tstate = PyThreadState_GET(); \ { PyThreadState* tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing) && !tstate->tracing && \ if (unlikely(tstate->use_tracing) && !tstate->tracing && \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
} \ } \
} }
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
#define __Pyx_TraceException() \ #define __Pyx_TraceException() \
if (likely(!__Pyx_use_tracing)); else { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing && \ if (tstate->use_tracing && \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
tstate->tracing++; \ tstate->tracing++; \
...@@ -130,14 +130,14 @@ ...@@ -130,14 +130,14 @@
if (CYTHON_TRACE_NOGIL) { \ if (CYTHON_TRACE_NOGIL) { \
PyThreadState *tstate; \ PyThreadState *tstate; \
PyGILState_STATE state = PyGILState_Ensure(); \ PyGILState_STATE state = PyGILState_Ensure(); \
tstate = PyThreadState_GET(); \ tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing) { \ if (tstate->use_tracing) { \
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
} \ } \
PyGILState_Release(state); \ PyGILState_Release(state); \
} \ } \
} else { \ } else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing) { \ if (tstate->use_tracing) { \
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
} \ } \
...@@ -146,7 +146,7 @@ ...@@ -146,7 +146,7 @@
#else #else
#define __Pyx_TraceReturn(result, nogil) \ #define __Pyx_TraceReturn(result, nogil) \
if (likely(!__Pyx_use_tracing)); else { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing) { \ if (tstate->use_tracing) { \
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
} \ } \
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
#endif #endif
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/ static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/
static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, const char *funcname, const char *srcfile, int firstlineno); /*proto*/ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, PyThreadState* tstate, const char *funcname, const char *srcfile, int firstlineno); /*proto*/
#else #else
...@@ -197,7 +197,7 @@ ...@@ -197,7 +197,7 @@
int ret = 0; \ int ret = 0; \
PyThreadState *tstate; \ PyThreadState *tstate; \
PyGILState_STATE state = PyGILState_Ensure(); \ PyGILState_STATE state = PyGILState_Ensure(); \
tstate = PyThreadState_GET(); \ tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \ if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \
ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
} \ } \
...@@ -205,7 +205,7 @@ ...@@ -205,7 +205,7 @@
if (unlikely(ret)) goto_error; \ if (unlikely(ret)) goto_error; \
} \ } \
} else { \ } else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \ if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
if (unlikely(ret)) goto_error; \ if (unlikely(ret)) goto_error; \
...@@ -215,7 +215,7 @@ ...@@ -215,7 +215,7 @@
#else #else
#define __Pyx_TraceLine(lineno, nogil, goto_error) \ #define __Pyx_TraceLine(lineno, nogil, goto_error) \
if (likely(!__Pyx_use_tracing)); else { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \ if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
if (unlikely(ret)) goto_error; \ if (unlikely(ret)) goto_error; \
...@@ -234,12 +234,12 @@ ...@@ -234,12 +234,12 @@
static int __Pyx_TraceSetupAndCall(PyCodeObject** code, static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
PyFrameObject** frame, PyFrameObject** frame,
PyThreadState* tstate,
const char *funcname, const char *funcname,
const char *srcfile, const char *srcfile,
int firstlineno) { int firstlineno) {
PyObject *type, *value, *traceback; PyObject *type, *value, *traceback;
int retval; int retval;
PyThreadState* tstate = PyThreadState_GET();
if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) { if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
if (*code == NULL) { if (*code == NULL) {
*code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno); *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
......
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