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

condvar.h 2.7 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  1. #ifndef Py_INTERNAL_CONDVAR_H
  2. #define Py_INTERNAL_CONDVAR_H
  3. #ifndef _POSIX_THREADS
  4. /* This means pthreads are not implemented in libc headers, hence the macro
  5. not present in unistd.h. But they still can be implemented as an external
  6. library (e.g. gnu pth in pthread emulation) */
  7. # ifdef HAVE_PTHREAD_H
  8. # include <pthread.h> /* _POSIX_THREADS */
  9. # endif
  10. #endif
  11. #ifdef _POSIX_THREADS
  12. /*
  13. * POSIX support
  14. */
  15. #define Py_HAVE_CONDVAR
  16. #include <pthread.h>
  17. #define PyMUTEX_T pthread_mutex_t
  18. #define PyCOND_T pthread_cond_t
  19. #elif defined(NT_THREADS)
  20. /*
  21. * Windows (XP, 2003 server and later, as well as (hopefully) CE) support
  22. *
  23. * Emulated condition variables ones that work with XP and later, plus
  24. * example native support on VISTA and onwards.
  25. */
  26. #define Py_HAVE_CONDVAR
  27. /* include windows if it hasn't been done before */
  28. #define WIN32_LEAN_AND_MEAN
  29. #include <windows.h>
  30. /* options */
  31. /* non-emulated condition variables are provided for those that want
  32. * to target Windows Vista. Modify this macro to enable them.
  33. */
  34. #ifndef _PY_EMULATED_WIN_CV
  35. #define _PY_EMULATED_WIN_CV 1 /* use emulated condition variables */
  36. #endif
  37. /* fall back to emulation if not targeting Vista */
  38. #if !defined NTDDI_VISTA || NTDDI_VERSION < NTDDI_VISTA
  39. #undef _PY_EMULATED_WIN_CV
  40. #define _PY_EMULATED_WIN_CV 1
  41. #endif
  42. #if _PY_EMULATED_WIN_CV
  43. typedef CRITICAL_SECTION PyMUTEX_T;
  44. /* The ConditionVariable object. From XP onwards it is easily emulated
  45. with a Semaphore.
  46. Semaphores are available on Windows XP (2003 server) and later.
  47. We use a Semaphore rather than an auto-reset event, because although
  48. an auto-resent event might appear to solve the lost-wakeup bug (race
  49. condition between releasing the outer lock and waiting) because it
  50. maintains state even though a wait hasn't happened, there is still
  51. a lost wakeup problem if more than one thread are interrupted in the
  52. critical place. A semaphore solves that, because its state is
  53. counted, not Boolean.
  54. Because it is ok to signal a condition variable with no one
  55. waiting, we need to keep track of the number of
  56. waiting threads. Otherwise, the semaphore's state could rise
  57. without bound. This also helps reduce the number of "spurious wakeups"
  58. that would otherwise happen.
  59. */
  60. typedef struct _PyCOND_T
  61. {
  62. HANDLE sem;
  63. int waiting; /* to allow PyCOND_SIGNAL to be a no-op */
  64. } PyCOND_T;
  65. #else /* !_PY_EMULATED_WIN_CV */
  66. /* Use native Win7 primitives if build target is Win7 or higher */
  67. /* SRWLOCK is faster and better than CriticalSection */
  68. typedef SRWLOCK PyMUTEX_T;
  69. typedef CONDITION_VARIABLE PyCOND_T;
  70. #endif /* _PY_EMULATED_WIN_CV */
  71. #endif /* _POSIX_THREADS, NT_THREADS */
  72. #endif /* Py_INTERNAL_CONDVAR_H */
Tip!

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

Comments

Loading...