Commits

Anonymous committed d96ce97

Add a new API, PyThreadState_DeleteCurrent() that combines
PyThreadState_Delete() and PyEval_ReleaseLock(). It is only defined
if WITH_THREAD is defined.

Comments (0)

Files changed (2)

Include/pystate.h

 DL_IMPORT(PyThreadState *) PyThreadState_New(PyInterpreterState *);
 DL_IMPORT(void) PyThreadState_Clear(PyThreadState *);
 DL_IMPORT(void) PyThreadState_Delete(PyThreadState *);
+#ifdef WITH_THREAD
+DL_IMPORT(void) PyThreadState_DeleteCurrent(void);
+#endif
 
 DL_IMPORT(PyThreadState *) PyThreadState_Get(void);
 DL_IMPORT(PyThreadState *) PyThreadState_Swap(PyThreadState *);
 }
 
 
-void
-PyThreadState_Delete(PyThreadState *tstate)
+/* Common code for PyThreadState_Delete() and PyThreadState_DeleteCurrent() */
+static void
+tstate_delete_common(PyThreadState *tstate)
 {
 	PyInterpreterState *interp;
 	PyThreadState **p;
 	if (tstate == NULL)
 		Py_FatalError("PyThreadState_Delete: NULL tstate");
-	if (tstate == _PyThreadState_Current)
-		Py_FatalError("PyThreadState_Delete: tstate is still current");
 	interp = tstate->interp;
 	if (interp == NULL)
 		Py_FatalError("PyThreadState_Delete: NULL interp");
 }
 
 
+void
+PyThreadState_Delete(PyThreadState *tstate)
+{
+	if (tstate == _PyThreadState_Current)
+		Py_FatalError("PyThreadState_Delete: tstate is still current");
+	tstate_delete_common(tstate);
+}
+
+
+#ifdef WITH_THREAD
+void
+PyThreadState_DeleteCurrent()
+{
+	PyThreadState *tstate = _PyThreadState_Current;
+	if (tstate == NULL)
+		Py_FatalError(
+			"PyThreadState_DeleteCurrent: no current tstate");
+	_PyThreadState_Current = NULL;
+	tstate_delete_common(tstate);
+	PyEval_ReleaseLock();
+}
+#endif /* WITH_THREAD */
+
+
 PyThreadState *
 PyThreadState_Get(void)
 {