diff options
author | Alexey Kopytov <Alexey.Kopytov@Sun.com> | 2009-12-16 16:47:07 +0300 |
---|---|---|
committer | Alexey Kopytov <Alexey.Kopytov@Sun.com> | 2009-12-16 16:47:07 +0300 |
commit | f1e83a4163458f7e25c709403cc7c7b48a7ef23e (patch) | |
tree | fa68ffcd1dbdaf248e483a5692358fe7330ec507 /mysys/my_winthread.c | |
parent | bcedf962ff7d22dd4d921a099fa38feeacc01b0b (diff) | |
parent | 8b19de0de10094b25be63cd6a9a1d61517602f0b (diff) | |
download | mariadb-git-f1e83a4163458f7e25c709403cc7c7b48a7ef23e.tar.gz |
Manual merge of mysql-5.1-bugteam into mysql-trunk-merge.
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 9e8458b0799..290351099a4 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 |