summaryrefslogtreecommitdiff
path: root/mysys/my_winthread.c
diff options
context:
space:
mode:
authorVladislav Vaintroub <vvaintroub@mysql.com>2009-12-19 14:11:48 +0100
committerVladislav Vaintroub <vvaintroub@mysql.com>2009-12-19 14:11:48 +0100
commit3de04825514e4dc3fd6f1a8f5eb18a280f817699 (patch)
treed5461ec6ad35812385dd5cfef327052838c471b4 /mysys/my_winthread.c
parent4f233c43b11b6f4f159350a192fa3fb3e3ce6c9a (diff)
parent02b76970c5da2b836d322e4189cdde79a5c15f4c (diff)
downloadmariadb-git-3de04825514e4dc3fd6f1a8f5eb18a280f817699.tar.gz
merge
Diffstat (limited to 'mysys/my_winthread.c')
-rw-r--r--mysys/my_winthread.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c
index 9fb1dd14b6c..aecb2f7cc78 100644
--- a/mysys/my_winthread.c
+++ b/mysys/my_winthread.c
@@ -147,4 +147,35 @@ int pthread_cancel(pthread_t thread)
errno= EINVAL;
return -1;
}
+
+/*
+ One time initialization. For simplicity, we assume initializer thread
+ does not exit within init_routine().
+*/
+int my_pthread_once(my_pthread_once_t *once_control,
+ void (*init_routine)(void))
+{
+ LONG state= InterlockedCompareExchange(once_control, MY_PTHREAD_ONCE_INPROGRESS,
+ MY_PTHREAD_ONCE_INIT);
+ switch(state)
+ {
+ case MY_PTHREAD_ONCE_INIT:
+ /* This is initializer thread */
+ (*init_routine)();
+ *once_control= MY_PTHREAD_ONCE_DONE;
+ break;
+
+ case MY_PTHREAD_ONCE_INPROGRESS:
+ /* init_routine in progress. Wait for its completion */
+ while(*once_control == MY_PTHREAD_ONCE_INPROGRESS)
+ {
+ Sleep(1);
+ }
+ break;
+ case MY_PTHREAD_ONCE_DONE:
+ /* Nothing to do */
+ break;
+ }
+ return 0;
+}
#endif