summaryrefslogtreecommitdiff
path: root/mysys/my_winthread.c
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@montyprogram.com>2011-06-12 16:09:28 +0200
committerVladislav Vaintroub <wlad@montyprogram.com>2011-06-12 16:09:28 +0200
commitfe054adfcaecbd891da802517826a951bb4ca377 (patch)
treee70229f726e1111ee3e03d914c8847bf249ac0e2 /mysys/my_winthread.c
parent824ce5f3eae52ee418665211c24218a5772c43f2 (diff)
downloadmariadb-git-fe054adfcaecbd891da802517826a951bb4ca377.tar.gz
Backport fix for MySQL bug #56405 :
use native windows condition variables and rwlocks in mysys, if Windows supports it.
Diffstat (limited to 'mysys/my_winthread.c')
-rw-r--r--mysys/my_winthread.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c
index 6adf24ef543..5fbad39597c 100644
--- a/mysys/my_winthread.c
+++ b/mysys/my_winthread.c
@@ -156,8 +156,19 @@ int win_pthread_setspecific(void *a,void *b,uint length)
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);
+ LONG state;
+
+ /*
+ Do "dirty" read to find out if initialization is already done, to
+ save an interlocked operation in common case. Memory barriers are ensured by
+ Visual C++ volatile implementation.
+ */
+ if (*once_control == MY_PTHREAD_ONCE_DONE)
+ return 0;
+
+ state= InterlockedCompareExchange(once_control, MY_PTHREAD_ONCE_INPROGRESS,
+ MY_PTHREAD_ONCE_INIT);
+
switch(state)
{
case MY_PTHREAD_ONCE_INIT: