summaryrefslogtreecommitdiffstats
path: root/common/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/thread.c')
-rw-r--r--common/thread.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/thread.c b/common/thread.c
index 2cf4321..d6d6c1a 100644
--- a/common/thread.c
+++ b/common/thread.c
@@ -81,3 +81,19 @@ void mutex_unlock(mutex_t* mutex)
81 pthread_mutex_unlock(mutex); 81 pthread_mutex_unlock(mutex);
82#endif 82#endif
83} 83}
84
85void thread_once(thread_once_t *once_control, void (*init_routine)(void))
86{
87#ifdef WIN32
88 while (InterlockedExchange(&(once_control->lock), 1) != 0) {
89 Sleep(1);
90 }
91 if (!once_control->state) {
92 once_control->state = 1;
93 init_routine();
94 }
95 InterlockedExchange(&(once_control->lock), 0);
96#else
97 pthread_once(once_control, init_routine);
98#endif
99}