Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:44

0001 #ifndef Py_INTERNAL_GIL_H
0002 #define Py_INTERNAL_GIL_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006 
0007 #ifndef Py_BUILD_CORE
0008 #  error "this header requires Py_BUILD_CORE define"
0009 #endif
0010 
0011 #include "pycore_atomic.h"    /* _Py_atomic_address */
0012 #include "pycore_condvar.h"   /* PyCOND_T */
0013 
0014 #ifndef Py_HAVE_CONDVAR
0015 #  error You need either a POSIX-compatible or a Windows system!
0016 #endif
0017 
0018 /* Enable if you want to force the switching of threads at least
0019    every `interval`. */
0020 #undef FORCE_SWITCHING
0021 #define FORCE_SWITCHING
0022 
0023 struct _gil_runtime_state {
0024     /* microseconds (the Python API uses seconds, though) */
0025     unsigned long interval;
0026     /* Last PyThreadState holding / having held the GIL. This helps us
0027        know whether anyone else was scheduled after we dropped the GIL. */
0028     _Py_atomic_address last_holder;
0029     /* Whether the GIL is already taken (-1 if uninitialized). This is
0030        atomic because it can be read without any lock taken in ceval.c. */
0031     _Py_atomic_int locked;
0032     /* Number of GIL switches since the beginning. */
0033     unsigned long switch_number;
0034     /* This condition variable allows one or several threads to wait
0035        until the GIL is released. In addition, the mutex also protects
0036        the above variables. */
0037     PyCOND_T cond;
0038     PyMUTEX_T mutex;
0039 #ifdef FORCE_SWITCHING
0040     /* This condition variable helps the GIL-releasing thread wait for
0041        a GIL-awaiting thread to be scheduled and take the GIL. */
0042     PyCOND_T switch_cond;
0043     PyMUTEX_T switch_mutex;
0044 #endif
0045 };
0046 
0047 #ifdef __cplusplus
0048 }
0049 #endif
0050 #endif /* !Py_INTERNAL_GIL_H */