summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2013-03-23 10:36:16 (GMT)
committerKristján Valur Jónsson <sweskman@gmail.com>2013-03-23 10:36:16 (GMT)
commit684cd0e64311faafba989457e28fbf2e84faa62e (patch)
treec5d7122fb92223ede065f704ac6cffea0ceebd71 /Python/pystate.c
parentd4296fc19c20525215a26ad639be33e7fb53a898 (diff)
downloadcpython-684cd0e64311faafba989457e28fbf2e84faa62e.zip
cpython-684cd0e64311faafba989457e28fbf2e84faa62e.tar.gz
cpython-684cd0e64311faafba989457e28fbf2e84faa62e.tar.bz2
Issue #17522: Add the PyGILState_Check() API.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index cfd61d0..7003893 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)
{