[vlc-commits] win32: run-time fallback for condition variable
Rémi Denis-Courmont
git at videolan.org
Fri May 27 23:43:03 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri May 27 22:42:25 2016 +0300| [77d086039605d1743f9fece4054ac699cb90f19e] | committer: Rémi Denis-Courmont
win32: run-time fallback for condition variable
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=77d086039605d1743f9fece4054ac699cb90f19e
---
src/win32/thread.c | 43 +++++++++++++++++++++++++++++++++++++------
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 4920366..a2597e2 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -440,7 +440,33 @@ retry:
vlc_mutex_unlock(&super_mutex);
}
-#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
+/*** Condition variables (low-level) ***/
+#if (_WIN32_WINNT < _WIN32_WINNT_VISTA)
+static VOID (WINAPI *InitializeConditionVariable_)(PCONDITION_VARIABLE);
+#define InitializeConditionVariable InitializeConditionVariable_
+static BOOL (WINAPI *SleepConditionVariableCS_)(PCONDITION_VARIABLE,
+ PCRITICAL_SECTION, DWORD);
+#define SleepConditionVariableCS SleepConditionVariableCS_
+static VOID (WINAPI *WakeAllConditionVariable_)(PCONDITION_VARIABLE);
+#define WakeAllConditionVariable WakeAllConditionVariable_
+
+static void WINAPI DummyConditionVariable(CONDITION_VARIABLE *cv)
+{
+ (void) cv;
+}
+
+static BOOL WINAPI SleepConditionVariableFallback(CONDITION_VARIABLE *cv,
+ CRITICAL_SECTION *cs,
+ DWORD ms)
+{
+ (void) cv;
+ LeaveCriticalSection(cs);
+ SleepEx(0, TRUE);
+ EnterCriticalSection(cs);
+ return ms != 0;
+}
+#endif
+
/*** Futeces^WAddress waits ***/
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
static BOOL (WINAPI *WaitOnAddress_)(VOID volatile *, PVOID, SIZE_T, DWORD);
@@ -577,7 +603,6 @@ void vlc_addr_broadcast(void *addr)
{
WakeByAddressAll(addr);
}
-#endif
/*** Threads ***/
#if !IS_INTERRUPTIBLE
@@ -1162,7 +1187,6 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
{
case DLL_PROCESS_ATTACH:
{
-#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
HANDLE h = GetModuleHandle(TEXT("kernel32.dll"));
if (unlikely(h == NULL))
@@ -1171,13 +1195,22 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
if (!LOOKUP(WaitOnAddress)
|| !LOOKUP(WakeByAddressAll) || !LOOKUP(WakeByAddressSingle))
{
+# if (_WIN32_WINNT < _WIN32_WINNT_VISTA)
+ if (!LOOKUP(InitializeConditionVariable)
+ || !LOOKUP(SleepConditionVariableCS)
+ || !LOOKUP(WakeAllConditionVariable))
+ {
+ InitializeConditionVariable_ = DummyConditionVariable;
+ SleepConditionVariableCS_ = SleepConditionVariableFallback;
+ WakeAllConditionVariable_ = DummyConditionVariable;
+ }
+# endif
vlc_wait_addr_init();
WaitOnAddress_ = WaitOnAddressFallback;
WakeByAddressAll_ = WakeByAddressFallback;
WakeByAddressSingle_ = WakeByAddressFallback;
}
#endif
-#endif
thread_key = TlsAlloc();
if (unlikely(thread_key == TLS_OUT_OF_INDEXES))
return FALSE;
@@ -1195,12 +1228,10 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
vlc_mutex_destroy (&super_mutex);
DeleteCriticalSection (&clock_lock);
TlsFree(thread_key);
-#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
if (WaitOnAddress_ == WaitOnAddressFallback)
vlc_wait_addr_deinit();
#endif
-#endif
break;
case DLL_THREAD_DETACH:
More information about the vlc-commits
mailing list