/** * Check if the current thread has the lock * @return True if the current thread holds the GIL, false otherwise */ bool PythonGIL::locked() { #if PY_VERSION_HEX < 0x03000000 PyThreadState *ts = _PyThreadState_Current; return (ts && ts == PyGILState_GetThisThreadState()); #else return (PyGILState_Check() == 1); #endif }
static void bpo20891_thread(void *lockp) { PyThread_type_lock lock = *((PyThread_type_lock*)lockp); PyGILState_STATE state = PyGILState_Ensure(); if (!PyGILState_Check()) { fprintf(stderr, "PyGILState_Check failed!"); abort(); } PyGILState_Release(state); PyThread_release_lock(lock); PyThread_exit_thread(); }
/* Return information about a file. On POSIX, use fstat(). On Windows, use GetFileType() and GetFileInformationByHandle() which support files larger than 2 GiB. fstat() may fail with EOVERFLOW on files larger than 2 GiB because the file size type is a signed 32-bit integer: see issue #23152. Raise an exception and return -1 on error. On Windows, set the last Windows error on error. On POSIX, set errno on error. Fill status and return 0 on success. Release the GIL to call GetFileType() and GetFileInformationByHandle(), or to call fstat(). The caller must hold the GIL. */ int _Py_fstat(int fd, struct _Py_stat_struct *status) { int res; assert(PyGILState_Check()); Py_BEGIN_ALLOW_THREADS res = _Py_fstat_noraise(fd, status); Py_END_ALLOW_THREADS if (res != 0) { #ifdef MS_WINDOWS PyErr_SetFromWindowsErr(0); #else PyErr_SetFromErrno(PyExc_OSError); #endif return -1; } return 0; }