diff options
author | Alexander Nozdrin <alik@sun.com> | 2009-12-16 21:02:21 +0300 |
---|---|---|
committer | Alexander Nozdrin <alik@sun.com> | 2009-12-16 21:02:21 +0300 |
commit | 5f0c09dd7220b7ad5709823788e9289fc94ab8fe (patch) | |
tree | c656767fe54a976ffb669926348b9fac198be312 /mysys/my_winthread.c | |
parent | 5194074be762f169fcc25b9ad0d4013905ba0655 (diff) | |
parent | f1e83a4163458f7e25c709403cc7c7b48a7ef23e (diff) | |
download | mariadb-git-5f0c09dd7220b7ad5709823788e9289fc94ab8fe.tar.gz |
Manual merge from mysql-trunk-merge.
Conflicts:
- include/my_no_pthread.h
- mysql-test/r/sp-ucs2.result
- sql/log.cc
- sql/sql_acl.cc
- sql/sql_yacc.yy
Diffstat (limited to 'mysys/my_winthread.c')
-rw-r--r-- | mysys/my_winthread.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c index f3d643975b3..6b7a51e7755 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -129,4 +129,36 @@ error_return: 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 |