diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2018-09-24 17:26:33 +0300 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2018-09-26 16:31:16 +0300 |
commit | a6853a944892d370b3969e97fdcdacd5a3718034 (patch) | |
tree | f315605cfdb15846738f55d11589d52ec2ac2806 /src/win32 | |
parent | cbeac008b7f5fd4970b67af619f73775ec7076a0 (diff) |
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 <derek.buitenhuis@gmail.com>
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/thread.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/win32/thread.c b/src/win32/thread.c index c73dba1..41a04e5 100644 --- a/src/win32/thread.c +++ b/src/win32/thread.c @@ -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 |