diff options
author | unknown <knielsen@knielsen-hq.org> | 2010-03-04 09:03:07 +0100 |
---|---|---|
committer | unknown <knielsen@knielsen-hq.org> | 2010-03-04 09:03:07 +0100 |
commit | 4bf849c23c2fe2174016da630705a362f76d3922 (patch) | |
tree | f39b89f218ff81ceb62349eb225a455d52c3ba78 /mysys/my_winthread.c | |
parent | f04cf03f75ffca0b99562c027c1c57340d375f66 (diff) | |
parent | 62db6839b82d824567979ef3e05caccd67ed11ec (diff) | |
download | mariadb-git-4bf849c23c2fe2174016da630705a362f76d3922.tar.gz |
Merge MySQL 5.1.44 into MariaDB.
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 8bda595451b..6adf24ef543 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -148,4 +148,36 @@ int win_pthread_setspecific(void *a,void *b,uint length) return 0; } + +/* + 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 |