29 #ifndef COMPAT_W32PTHREADS_H
30 #define COMPAT_W32PTHREADS_H
38 #define WIN32_LEAN_AND_MEAN
42 #if _WIN32_WINNT < 0x0600 && defined(__MINGW32__)
44 #define MemoryBarrier __sync_synchronize
54 void *(*func)(
void*
arg);
65 #if HAVE_CONDITION_VARIABLE_PTR
73 #if _WIN32_WINNT >= 0x0600
74 #define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0)
75 #define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE)
86 void *(*start_routine)(
void*),
void *
arg)
88 thread->
func = start_routine;
102 DWORD ret = WaitForSingleObject(thread.
handle, INFINITE);
103 if (ret != WAIT_OBJECT_0) {
104 if (ret == WAIT_ABANDONED)
110 *value_ptr = thread.
ret;
111 CloseHandle(thread.
handle);
117 InitializeCriticalSection(m);
122 DeleteCriticalSection(m);
127 EnterCriticalSection(m);
132 LeaveCriticalSection(m);
136 #if _WIN32_WINNT >= 0x0600
138 #define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT
143 InitOnceBeginInitialize(once_control, 0, &pending,
NULL);
146 InitOnceComplete(once_control, 0,
NULL);
152 InitializeConditionVariable(cond);
164 WakeAllConditionVariable(cond);
170 SleepConditionVariableCS(cond, mutex, INFINITE);
176 WakeConditionVariable(cond);
180 #else // _WIN32_WINNT < 0x0600
189 typedef union pthread_once_t {
194 #define PTHREAD_ONCE_INIT {0}
207 InterlockedExchange(state, 2);
229 if (initonce_begin && initonce_complete) {
231 initonce_begin(once_control, 0, &pending,
NULL);
234 initonce_complete(once_control, 0,
NULL);
276 cond->
Ptr = win32_cond;
311 if (cond_broadcast) {
312 cond_broadcast(cond);
329 WaitForSingleObject(win32_cond->
waiters_done, INFINITE);
343 cond_wait(cond, mutex, INFINITE);
356 WaitForSingleObject(win32_cond->
semaphore, INFINITE);
388 WaitForSingleObject(win32_cond->
waiters_done, INFINITE);
399 #if _WIN32_WINNT < 0x0600
400 HANDLE kernel_dll = GetModuleHandle(TEXT(
"kernel32.dll"));
403 (
void*)GetProcAddress(kernel_dll,
"InitializeConditionVariable");
405 (
void*)GetProcAddress(kernel_dll,
"WakeAllConditionVariable");
407 (
void*)GetProcAddress(kernel_dll,
"WakeConditionVariable");
409 (
void*)GetProcAddress(kernel_dll,
"SleepConditionVariableCS");
411 (
void*)GetProcAddress(kernel_dll,
"InitOnceBeginInitialize");
413 (
void*)GetProcAddress(kernel_dll,
"InitOnceComplete");
static BOOL(WINAPI *initonce_begin)(pthread_once_t *lpInitOnce
static av_unused void w32thread_init(void)
volatile int is_broadcast
static av_unused unsigned __stdcall attribute_align_arg win32thread_worker(void *arg)
Memory handling functions.
static av_unused int pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
LONG state
For the pre-Windows 6.0 compat code.
static av_unused int pthread_cond_destroy(pthread_cond_t *cond)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
volatile int waiter_count
Macro definitions for various function/variable attributes.
static pthread_mutex_t DWORD milliseconds
int(* cond)(enum AVPixelFormat pix_fmt)
static DWORD BOOL * fPending
static void w32thread_once_fallback(LONG volatile *state, void(*init_routine)(void))
CRITICAL_SECTION pthread_mutex_t
static av_unused int pthread_create(pthread_t *thread, const void *unused_attr, void *(*start_routine)(void *), void *arg)
static int pthread_mutex_init(pthread_mutex_t *m, void *attr)
void *(* func)(void *arg)
static int pthread_mutex_unlock(pthread_mutex_t *m)
static DWORD BOOL void ** lpContext
common internal API header
static int pthread_mutex_destroy(pthread_mutex_t *m)
static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
static pthread_mutex_t * mutex
pthread_mutex_t mtx_broadcast
static av_unused int pthread_cond_broadcast(pthread_cond_t *cond)
static int pthread_mutex_lock(pthread_mutex_t *m)
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
static LONG w32thread_init_state
static av_unused int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
static av_unused int pthread_join(pthread_t thread, void **value_ptr)
common internal and external API header
pthread_mutex_t mtx_waiter_count
void * Ptr
For the Windows 6.0+ native functions.
static av_unused int pthread_cond_signal(pthread_cond_t *cond)
#define InterlockedCompareExchange(x, y, z)