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(); }
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(); }
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; }