Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:46

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_condvar.h"       // PyCOND_T
0012 
0013 #ifndef Py_HAVE_CONDVAR
0014 #  error You need either a POSIX-compatible or a Windows system!
0015 #endif
0016 
0017 /* Enable if you want to force the switching of threads at least
0018    every `interval`. */
0019 #undef FORCE_SWITCHING
0020 #define FORCE_SWITCHING
0021 
0022 struct _gil_runtime_state {
0023 #ifdef Py_GIL_DISABLED
0024     /* If this GIL is disabled, enabled == 0.
0025 
0026        If this GIL is enabled transiently (most likely to initialize a module
0027        of unknown safety), enabled indicates the number of active transient
0028        requests.
0029 
0030        If this GIL is enabled permanently, enabled == INT_MAX.
0031 
0032        It must not be modified directly; use _PyEval_EnableGILTransiently(),
0033        _PyEval_EnableGILPermanently(), and _PyEval_DisableGIL()
0034 
0035        It is always read and written atomically, but a thread can assume its
0036        value will be stable as long as that thread is attached or knows that no
0037        other threads are attached (e.g., during a stop-the-world.). */
0038     int enabled;
0039 #endif
0040     /* microseconds (the Python API uses seconds, though) */
0041     unsigned long interval;
0042     /* Last PyThreadState holding / having held the GIL. This helps us
0043        know whether anyone else was scheduled after we dropped the GIL. */
0044     PyThreadState* last_holder;
0045     /* Whether the GIL is already taken (-1 if uninitialized). This is
0046        atomic because it can be read without any lock taken in ceval.c. */
0047     int locked;
0048     /* Number of GIL switches since the beginning. */
0049     unsigned long switch_number;
0050     /* This condition variable allows one or several threads to wait
0051        until the GIL is released. In addition, the mutex also protects
0052        the above variables. */
0053     PyCOND_T cond;
0054     PyMUTEX_T mutex;
0055 #ifdef FORCE_SWITCHING
0056     /* This condition variable helps the GIL-releasing thread wait for
0057        a GIL-awaiting thread to be scheduled and take the GIL. */
0058     PyCOND_T switch_cond;
0059     PyMUTEX_T switch_mutex;
0060 #endif
0061 };
0062 
0063 #ifdef __cplusplus
0064 }
0065 #endif
0066 #endif /* !Py_INTERNAL_GIL_H */