Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gil.h 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  1. #ifndef Py_INTERNAL_GIL_H
  2. #define Py_INTERNAL_GIL_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "pyatomic.h"
  7. #include "internal/condvar.h"
  8. #ifndef Py_HAVE_CONDVAR
  9. #error You need either a POSIX-compatible or a Windows system!
  10. #endif
  11. /* Enable if you want to force the switching of threads at least
  12. every `interval`. */
  13. #undef FORCE_SWITCHING
  14. #define FORCE_SWITCHING
  15. struct _gil_runtime_state {
  16. /* microseconds (the Python API uses seconds, though) */
  17. unsigned long interval;
  18. /* Last PyThreadState holding / having held the GIL. This helps us
  19. know whether anyone else was scheduled after we dropped the GIL. */
  20. _Py_atomic_address last_holder;
  21. /* Whether the GIL is already taken (-1 if uninitialized). This is
  22. atomic because it can be read without any lock taken in ceval.c. */
  23. _Py_atomic_int locked;
  24. /* Number of GIL switches since the beginning. */
  25. unsigned long switch_number;
  26. /* This condition variable allows one or several threads to wait
  27. until the GIL is released. In addition, the mutex also protects
  28. the above variables. */
  29. PyCOND_T cond;
  30. PyMUTEX_T mutex;
  31. #ifdef FORCE_SWITCHING
  32. /* This condition variable helps the GIL-releasing thread wait for
  33. a GIL-awaiting thread to be scheduled and take the GIL. */
  34. PyCOND_T switch_cond;
  35. PyMUTEX_T switch_mutex;
  36. #endif
  37. };
  38. #ifdef __cplusplus
  39. }
  40. #endif
  41. #endif /* !Py_INTERNAL_GIL_H */
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...