Commit a6853a94 authored by Derek Buitenhuis's avatar Derek Buitenhuis

win32: Add implementation of pthread_once

This function will be required to make dav1d_init threadsafe.

Full erro checking support is included in this implementation,
for completeness, even though dav1d_init cannot fail, and thus
will ignore the return value of pthread_once.
Signed-off-by: Derek Buitenhuis's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parent cbeac008
......@@ -32,8 +32,11 @@
#include <windows.h>
#define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT
typedef CRITICAL_SECTION pthread_mutex_t;
typedef CONDITION_VARIABLE pthread_cond_t;
typedef INIT_ONCE pthread_once_t;
typedef void *pthread_t;
typedef void *pthread_mutexattr_t;
typedef void *pthread_condattr_t;
......@@ -54,6 +57,8 @@ int pthread_create(pthread_t* thread, const pthread_attr_t* attr,
void*(*proc)(void*), void* param);
void pthread_join(pthread_t thread, void** res);
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
#else
#include <pthread.h>
......
......@@ -125,4 +125,23 @@ void pthread_join(pthread_t thread, void** res)
free(th);
}
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
{
BOOL fPending = FALSE;
BOOL fStatus;
fStatus = InitOnceBeginInitialize(once_control, 0, &fPending, NULL);
if (fStatus != TRUE)
return EINVAL;
if (fPending == TRUE)
init_routine();
fStatus = InitOnceComplete(once_control, 0, NULL);
if (!fStatus)
return EINVAL;
return 0;
}
#endif
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