29 #ifndef LIBAV_COMPAT_W32PTHREADS_H 30 #define LIBAV_COMPAT_W32PTHREADS_H 38 #define WIN32_LEAN_AND_MEAN 42 #if _WIN32_WINNT < 0x0600 && defined(__MINGW32__) 44 #define MemoryBarrier __sync_synchronize 53 void *(*func)(
void*
arg);
64 #if HAVE_CONDITION_VARIABLE_PTR 72 #if _WIN32_WINNT >= 0x0600 73 #define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0) 74 #define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE) 85 void *(*start_routine)(
void*),
void *
arg)
87 thread->
func = start_routine;
96 DWORD
ret = WaitForSingleObject(thread.
handle, INFINITE);
97 if (ret != WAIT_OBJECT_0)
100 *value_ptr = thread.
ret;
101 CloseHandle(thread.
handle);
106 InitializeCriticalSection(m);
111 DeleteCriticalSection(m);
116 EnterCriticalSection(m);
121 LeaveCriticalSection(m);
125 #if _WIN32_WINNT >= 0x0600 128 #define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT 132 BOOL pending = FALSE;
133 InitOnceBeginInitialize(once_control, 0, &pending,
NULL);
136 InitOnceComplete(once_control, 0,
NULL);
142 InitializeConditionVariable(cond);
153 WakeAllConditionVariable(cond);
158 SleepConditionVariableCS(cond, mutex, INFINITE);
164 WakeConditionVariable(cond);
167 #else // _WIN32_WINNT < 0x0600 176 typedef union pthread_once_t {
181 #define PTHREAD_ONCE_INIT {0} 185 static BOOL (WINAPI *initonce_complete)(pthread_once_t *lpInitOnce, DWORD
dwFlags,
void *
lpContext);
190 switch (InterlockedCompareExchange(state, 1, 0)) {
194 InterlockedExchange(state, 2);
216 if (initonce_begin && initonce_complete) {
217 BOOL pending = FALSE;
218 initonce_begin(once_control, 0, &pending,
NULL);
221 initonce_complete(once_control, 0,
NULL);
263 cond->
Ptr = win32_cond;
296 if (cond_broadcast) {
297 cond_broadcast(cond);
314 WaitForSingleObject(win32_cond->
waiters_done, INFINITE);
327 cond_wait(cond, mutex, INFINITE);
340 WaitForSingleObject(win32_cond->
semaphore, INFINITE);
372 WaitForSingleObject(win32_cond->
waiters_done, INFINITE);
382 #if _WIN32_WINNT < 0x0600 383 HANDLE kernel_dll = GetModuleHandle(TEXT(
"kernel32.dll"));
static av_unused void pthread_cond_signal(pthread_cond_t *cond)
static BOOL(WINAPI *initonce_begin)(pthread_once_t *lpInitOnce
static av_unused void w32thread_init(void)
volatile int is_broadcast
static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
static av_unused unsigned __stdcall attribute_align_arg win32thread_worker(void *arg)
memory handling functions
static av_unused void pthread_cond_broadcast(pthread_cond_t *cond)
volatile int waiter_count
Macro definitions for various function/variable attributes.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static pthread_mutex_t DWORD milliseconds
static DWORD BOOL * fPending
static void w32thread_once_fallback(LONG volatile *state, void(*init_routine)(void))
CRITICAL_SECTION pthread_mutex_t
void * Ptr
For the Windows 6.0+ native functions.
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)
static int pthread_mutex_unlock(pthread_mutex_t *m)
static DWORD BOOL void ** lpContext
static av_unused void pthread_join(pthread_t thread, void **value_ptr)
common internal API header
static int pthread_mutex_destroy(pthread_mutex_t *m)
static av_unused void pthread_cond_destroy(pthread_cond_t *cond)
static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
void *(* func)(void *arg)
static pthread_mutex_t * mutex
pthread_mutex_t mtx_broadcast
#define attribute_align_arg
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))
LONG state
For the pre-Windows 6.0 compat code.
pthread_mutex_t mtx_waiter_count
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...