diff options
author | Mohan Embar <gnustuff@thisiscool.com> | 2003-10-31 03:36:38 +0000 |
---|---|---|
committer | Mohan Embar <membar@gcc.gnu.org> | 2003-10-31 03:36:38 +0000 |
commit | d6bc9793de3e1b429e68fe2166ed01206e9c57db (patch) | |
tree | ab5178c3a445c4eabae09bbe11ede4c98ba1445d /libjava/win32-threads.cc | |
parent | 748e241eab69462ae57751a8b8ce58bba4ceb520 (diff) | |
download | gcc-d6bc9793de3e1b429e68fe2166ed01206e9c57db.zip gcc-d6bc9793de3e1b429e68fe2166ed01206e9c57db.tar.gz gcc-d6bc9793de3e1b429e68fe2166ed01206e9c57db.tar.bz2 |
re PR libgcj/12647 ([win32] wait() does not release monitor correctly)
PR libgcj/12647:
* win32-threads.cc (_Jv_CondWait): Respect mutex's
refcount when releasing and reacquiring it.
From-SVN: r73118
Diffstat (limited to 'libjava/win32-threads.cc')
-rw-r--r-- | libjava/win32-threads.cc | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/libjava/win32-threads.cc b/libjava/win32-threads.cc index 1f3d0c5..9e3981d 100644 --- a/libjava/win32-threads.cc +++ b/libjava/win32-threads.cc @@ -126,7 +126,18 @@ _Jv_CondWait(_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu, jlong millis, jint na else if (millis == 0) time = INFINITE; else time = millis; - _Jv_MutexUnlock (mu); + // Record the current lock depth, so it can be restored + // when we reacquire it. + int count = mu->refcount; + int curcount = count; + + // Call _Jv_MutexUnlock repeatedly until this thread + // has completely released the monitor. + while (curcount > 0) + { + _Jv_MutexUnlock (mu); + --curcount; + } // Set up our array of three events: // - the auto-reset event (for notify()) @@ -164,7 +175,13 @@ _Jv_CondWait(_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu, jlong millis, jint na if (last_waiter) ResetEvent (cv->ev[1]); - _Jv_MutexLock (mu); + // Call _Jv_MutexLock repeatedly until the mutex's refcount is the + // same as before we originally released it. + while (curcount < count) + { + _Jv_MutexLock (mu); + ++curcount; + } return interrupted ? _JV_INTERRUPTED : 0; } |