#ifndef Py_INTERNAL_GIL_H1#define Py_INTERNAL_GIL_H2#ifdef __cplusplus3extern "C" {4#endif56#ifndef Py_BUILD_CORE7# error "this header requires Py_BUILD_CORE define"8#endif910#include "pycore_atomic.h" /* _Py_atomic_address */11#include "pycore_condvar.h" /* PyCOND_T */1213#ifndef Py_HAVE_CONDVAR14# error You need either a POSIX-compatible or a Windows system!15#endif1617/* Enable if you want to force the switching of threads at least18every `interval`. */19#undef FORCE_SWITCHING20#define FORCE_SWITCHING2122struct _gil_runtime_state {23/* microseconds (the Python API uses seconds, though) */24unsigned long interval;25/* Last PyThreadState holding / having held the GIL. This helps us26know whether anyone else was scheduled after we dropped the GIL. */27_Py_atomic_address last_holder;28/* Whether the GIL is already taken (-1 if uninitialized). This is29atomic because it can be read without any lock taken in ceval.c. */30_Py_atomic_int locked;31/* Number of GIL switches since the beginning. */32unsigned long switch_number;33/* This condition variable allows one or several threads to wait34until the GIL is released. In addition, the mutex also protects35the above variables. */36PyCOND_T cond;37PyMUTEX_T mutex;38#ifdef FORCE_SWITCHING39/* This condition variable helps the GIL-releasing thread wait for40a GIL-awaiting thread to be scheduled and take the GIL. */41PyCOND_T switch_cond;42PyMUTEX_T switch_mutex;43#endif44};4546#ifdef __cplusplus47}48#endif49#endif /* !Py_INTERNAL_GIL_H */505152