aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKO Myung-Hun <komh78@gmail.com>2015-11-12 12:31:51 +0900
committerMichael Niedermayer <michael@niedermayer.cc>2015-11-12 22:31:46 +0100
commit6248f23859eb610079b1964e5f081ff0e9c62281 (patch)
tree81f85e0c3ae0ba1be22386775f30f09a3b69ade7
parentb1a32429ef6ccd94673e4c36924ad0949f4d50a1 (diff)
downloadffmpeg-6248f23859eb610079b1964e5f081ff0e9c62281.tar.gz
os2threads: Add pthread_once()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--compat/os2threads.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/compat/os2threads.h b/compat/os2threads.h
index 5b6ca5579d..f8fb2c8c63 100644
--- a/compat/os2threads.h
+++ b/compat/os2threads.h
@@ -32,6 +32,8 @@
#undef __STRICT_ANSI__ /* for _beginthread() */
#include <stdlib.h>
+#include <sys/fmutex.h>
+
#include "libavutil/mem.h"
typedef TID pthread_t;
@@ -47,6 +49,13 @@ typedef struct {
typedef void pthread_condattr_t;
+typedef struct {
+ volatile int done;
+ _fmutex mtx;
+} pthread_once_t;
+
+#define PTHREAD_ONCE_INIT {0, _FMUTEX_INITIALIZER}
+
struct thread_arg {
void *(*start_routine)(void *);
void *arg;
@@ -163,4 +172,22 @@ static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mute
return 0;
}
+static av_always_inline int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
+{
+ if (!once_control->done)
+ {
+ _fmutex_request(&once_control->mtx, 0);
+
+ if (!once_control->done)
+ {
+ init_routine();
+
+ once_control->done = 1;
+ }
+
+ _fmutex_release(&once_control->mtx);
+ }
+
+ return 0;
+}
#endif /* AVCODEC_OS2PTHREADS_H */