]> git.sesse.net Git - ffmpeg/blobdiff - compat/w32pthreads.h
cbs_h265: Fix reading of unknown parameter set extension data
[ffmpeg] / compat / w32pthreads.h
index a1cb396d6ec1461509404d71e6f2b277cc89b1dd..f38f767d8fb459e03edea3a77ebb3ea75c12b2bc 100644 (file)
 #include <windows.h>
 #include <process.h>
 
+#if _WIN32_WINNT < 0x0600 && defined(__MINGW32__)
+#undef MemoryBarrier
+#define MemoryBarrier __sync_synchronize
+#endif
+
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
@@ -160,6 +165,11 @@ static inline void pthread_cond_signal(pthread_cond_t *cond)
 }
 
 #else // _WIN32_WINNT < 0x0600
+
+/* atomic init state of dynamically loaded functions */
+static LONG w32thread_init_state = 0;
+static av_unused void w32thread_init(void);
+
 /* for pre-Windows 6.0 platforms, define INIT_ONCE struct,
  * compatible to the one used in the native API */
 
@@ -200,6 +210,8 @@ static inline void w32thread_once_fallback(LONG volatile *state, void (*init_rou
 
 static av_unused int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
 {
+    w32thread_once_fallback(&w32thread_init_state, w32thread_init);
+
     /* Use native functions on Windows 6.0+ */
     if (initonce_begin && initonce_complete) {
         BOOL pending = FALSE;
@@ -236,6 +248,9 @@ static BOOL (WINAPI *cond_wait)(pthread_cond_t *cond, pthread_mutex_t *mutex,
 static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
 {
     win32_cond_t *win32_cond = NULL;
+
+    w32thread_once_fallback(&w32thread_init_state, w32thread_init);
+
     if (cond_init) {
         cond_init(cond);
         return;
@@ -367,18 +382,18 @@ static av_unused void w32thread_init(void)
 #if _WIN32_WINNT < 0x0600
     HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll"));
     /* if one is available, then they should all be available */
-    cond_init      =
-        (void*)GetProcAddress(kernel_dll, "InitializeConditionVariable");
-    cond_broadcast =
-        (void*)GetProcAddress(kernel_dll, "WakeAllConditionVariable");
-    cond_signal    =
-        (void*)GetProcAddress(kernel_dll, "WakeConditionVariable");
-    cond_wait      =
-        (void*)GetProcAddress(kernel_dll, "SleepConditionVariableCS");
-    initonce_begin =
-        (void*)GetProcAddress(kernel_dll, "InitOnceBeginInitialize");
-    initonce_complete =
-        (void*)GetProcAddress(kernel_dll, "InitOnceComplete");
+    cond_init      = (void (WINAPI*)(pthread_cond_t *))
+        GetProcAddress(kernel_dll, "InitializeConditionVariable");
+    cond_broadcast = (void (WINAPI*)(pthread_cond_t *))
+        GetProcAddress(kernel_dll, "WakeAllConditionVariable");
+    cond_signal    = (void (WINAPI*)(pthread_cond_t *))
+        GetProcAddress(kernel_dll, "WakeConditionVariable");
+    cond_wait      = (BOOL (WINAPI*)(pthread_cond_t *, pthread_mutex_t *, DWORD))
+        GetProcAddress(kernel_dll, "SleepConditionVariableCS");
+    initonce_begin = (BOOL (WINAPI*)(pthread_once_t *, DWORD, BOOL *, void **))
+        GetProcAddress(kernel_dll, "InitOnceBeginInitialize");
+    initonce_complete = (BOOL (WINAPI*)(pthread_once_t *, DWORD, void *))
+        GetProcAddress(kernel_dll, "InitOnceComplete");
 #endif
 
 }