Commit 2830bce4 authored by Hendrik Leppkes's avatar Hendrik Leppkes Committed by Luca Barbato

w32pthreads: Load dynamically loaded functions on demand

This removes the requirement of calling w32thread_init before being
able to use the threading primitives.
Signed-off-by: 's avatarLuca Barbato <lu_zero@gentoo.org>
parent b22693b0
...@@ -160,6 +160,11 @@ static inline void pthread_cond_signal(pthread_cond_t *cond) ...@@ -160,6 +160,11 @@ static inline void pthread_cond_signal(pthread_cond_t *cond)
} }
#else // _WIN32_WINNT < 0x0600 #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, /* for pre-Windows 6.0 platforms, define INIT_ONCE struct,
* compatible to the one used in the native API */ * compatible to the one used in the native API */
...@@ -200,6 +205,8 @@ static inline void w32thread_once_fallback(LONG volatile *state, void (*init_rou ...@@ -200,6 +205,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)) 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+ */ /* Use native functions on Windows 6.0+ */
if (initonce_begin && initonce_complete) { if (initonce_begin && initonce_complete) {
BOOL pending = FALSE; BOOL pending = FALSE;
...@@ -236,6 +243,9 @@ static BOOL (WINAPI *cond_wait)(pthread_cond_t *cond, pthread_mutex_t *mutex, ...@@ -236,6 +243,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) static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
{ {
win32_cond_t *win32_cond = NULL; win32_cond_t *win32_cond = NULL;
w32thread_once_fallback(&w32thread_init_state, w32thread_init);
if (cond_init) { if (cond_init) {
cond_init(cond); cond_init(cond);
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment