Mercurial > cpython-lru_cache-weakref
diff Python/pystate.c @ 82889:2e92d1567ad7
Issue #17522: Add the PyGILState_Check() API.
| author | Kristján Valur Jónsson <sweskman@gmail.com> |
|---|---|
| date | Sat, 23 Mar 2013 03:36:16 -0700 |
| parents | 800507fb0a7e |
| children | 847692b9902a |
line wrap: on
line diff
--- a/Python/pystate.c Fri Mar 22 13:49:53 2013 -0700 +++ b/Python/pystate.c Sat Mar 23 03:36:16 2013 -0700 @@ -697,6 +697,15 @@ 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) {
