From 8dcde94c6068d7bb9c006091217617e2c11f75a9 Mon Sep 17 00:00:00 2001 From: Kristj?n Valur J?nsson Date: Sat, 23 Mar 2013 03:36:16 -0700 Subject: Issue #17522: Add the PyGILState_Check() API. --- Python/pystate.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index cfd61d0098..70038936d6 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -697,6 +697,15 @@ PyGILState_GetThisThreadState(void) return (PyThreadState *)PyThread_get_key_value(autoTLSkey); } +int +PyGILState_Check(void) +{ + /* can't use PyThreadState_Get() since it will assert that it has the GIL */ + PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed( + &_PyThreadState_Current); + return tstate && (tstate == PyGILState_GetThisThreadState()); +} + PyGILState_STATE PyGILState_Ensure(void) { -- cgit v1.2.1