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