Commit c6a51b04 authored by Sergei Golubchik's avatar Sergei Golubchik

fixes for hanging waiting_thread-t.c on windows

mysys/my_wincond.c:
  race condition: block gate could be left open forever, if cond_broadcast
  was done right after the last thread left WaitForMultipleObjects() on timeout
mysys/thr_rwlock.c:
  make rwlocks behave similar to their distant linux/solaris relatives
parent ade71b25
...@@ -126,7 +126,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, ...@@ -126,7 +126,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
EnterCriticalSection(&cond->lock_waiting); EnterCriticalSection(&cond->lock_waiting);
cond->waiting--; cond->waiting--;
if (cond->waiting == 0 && result == (WAIT_OBJECT_0+BROADCAST)) if (cond->waiting == 0)
{ {
/* /*
We're the last waiter to be notified or to stop waiting, so We're the last waiter to be notified or to stop waiting, so
......
...@@ -89,7 +89,7 @@ int my_rw_rdlock(rw_lock_t *rwp) ...@@ -89,7 +89,7 @@ int my_rw_rdlock(rw_lock_t *rwp)
pthread_mutex_lock(&rwp->lock); pthread_mutex_lock(&rwp->lock);
/* active or queued writers */ /* active or queued writers */
while (( rwp->state < 0 ) || rwp->waiters) while (( rwp->state < 0 ))
pthread_cond_wait( &rwp->readers, &rwp->lock); pthread_cond_wait( &rwp->readers, &rwp->lock);
rwp->state++; rwp->state++;
...@@ -101,7 +101,7 @@ int my_rw_tryrdlock(rw_lock_t *rwp) ...@@ -101,7 +101,7 @@ int my_rw_tryrdlock(rw_lock_t *rwp)
{ {
int res; int res;
pthread_mutex_lock(&rwp->lock); pthread_mutex_lock(&rwp->lock);
if ((rwp->state < 0 ) || rwp->waiters) if ((rwp->state < 0 ))
res= EBUSY; /* Can't get lock */ res= EBUSY; /* Can't get lock */
else else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment