/* Keep this as a static, as it is not reliable! It can only ever be compared to the state for the *current* thread. * If not equal, then it doesn't matter that the actual value may change immediately after comparison, as it can't possibly change to the current thread's state. * If equal, then the current thread holds the lock, so the value can't change until we yield the lock. */ static int PyThreadState_IsCurrent(PyThreadState *tstate) { /* Must be the tstate for this thread */ assert(PyGILState_GetThisThreadState()==tstate); return tstate == GET_TSTATE(); }
PyThreadState * PyThreadState_Get(void) { PyThreadState *tstate = GET_TSTATE(); if (tstate == NULL) Py_FatalError("PyThreadState_Get: no current thread"); return tstate; }
void PyThreadState_Delete(PyThreadState *tstate) { if (tstate == GET_TSTATE()) Py_FatalError("PyThreadState_Delete: tstate is still current"); #ifdef WITH_THREAD if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) PyThread_delete_key_value(autoTLSkey); #endif /* WITH_THREAD */ tstate_delete_common(tstate); }
void PyThreadState_Delete(PyThreadState *tstate) { if (tstate == GET_TSTATE()) Py_FatalError("PyThreadState_Delete: tstate is still current"); if (_PyRuntime.gilstate.autoInterpreterState && PyThread_tss_get(&_PyRuntime.gilstate.autoTSSkey) == tstate) { PyThread_tss_set(&_PyRuntime.gilstate.autoTSSkey, NULL); } tstate_delete_common(tstate); }
void PyThreadState_DeleteCurrent() { PyThreadState *tstate = GET_TSTATE(); if (tstate == NULL) Py_FatalError( "PyThreadState_DeleteCurrent: no current tstate"); tstate_delete_common(tstate); if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) PyThread_delete_key_value(autoTLSkey); SET_TSTATE(NULL); PyEval_ReleaseLock(); }
PyObject * PyThreadState_GetDict(void) { PyThreadState *tstate = GET_TSTATE(); if (tstate == NULL) return NULL; if (tstate->dict == NULL) { PyObject *d; tstate->dict = d = PyDict_New(); if (d == NULL) PyErr_Clear(); } return tstate->dict; }
void PyThreadState_DeleteCurrent() { PyThreadState *tstate = GET_TSTATE(); if (tstate == NULL) Py_FatalError( "PyThreadState_DeleteCurrent: no current tstate"); tstate_delete_common(tstate); if (_PyRuntime.gilstate.autoInterpreterState && PyThread_tss_get(&_PyRuntime.gilstate.autoTSSkey) == tstate) { PyThread_tss_set(&_PyRuntime.gilstate.autoTSSkey, NULL); } SET_TSTATE(NULL); PyEval_ReleaseLock(); }
int PyGILState_Check(void) { PyThreadState *tstate; if (!_PyGILState_check_enabled) return 1; if (autoTLSkey == -1) return 1; tstate = GET_TSTATE(); if (tstate == NULL) return 0; return (tstate == PyGILState_GetThisThreadState()); }
int PyGILState_Check(void) { PyThreadState *tstate; if (!_PyGILState_check_enabled) return 1; if (!PyThread_tss_is_created(&_PyRuntime.gilstate.autoTSSkey)) { return 1; } tstate = GET_TSTATE(); if (tstate == NULL) return 0; return (tstate == PyGILState_GetThisThreadState()); }
PyThreadState * PyThreadState_Swap(PyThreadState *newts) { PyThreadState *oldts = GET_TSTATE(); SET_TSTATE(newts); /* It should not be possible for more than one thread state to be used for a thread. Check this the best we can in debug builds. */ #if defined(Py_DEBUG) && defined(WITH_THREAD) if (newts) { /* This can be called from PyEval_RestoreThread(). Similar to it, we need to ensure errno doesn't change. */ int err = errno; PyThreadState *check = PyGILState_GetThisThreadState(); if (check && check->interp == newts->interp && check != newts) Py_FatalError("Invalid thread state for this thread"); errno = err; } #endif return oldts; }
PyThreadState * _PyThreadState_UncheckedGet(void) { return GET_TSTATE(); }
int PyGILState_Check(void) { PyThreadState *tstate = GET_TSTATE(); return tstate && (tstate == PyGILState_GetThisThreadState()); }