summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-12-15 03:43:43 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-12-15 03:43:43 +0000
commit70acb4837fa044641733d8ec42efc703c9a95f99 (patch)
tree1c04a48769763fccf4f871399260b51c7d8b5658
parente3b6b8d1e96479d0c7de03d5ec5ba21655e3a897 (diff)
downloadATCD-70acb4837fa044641733d8ec42efc703c9a95f99.tar.gz
*** empty log message ***
-rw-r--r--ChangeLog-98a10
-rw-r--r--ace/OS.h3
-rw-r--r--ace/OS.i44
3 files changed, 31 insertions, 26 deletions
diff --git a/ChangeLog-98a b/ChangeLog-98a
index c51a1390097..31221b10f25 100644
--- a/ChangeLog-98a
+++ b/ChangeLog-98a
@@ -1,13 +1,13 @@
-Sun Dec 14 15:00:14 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu>
+Sun Dec 14 21:37:08 1997 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
* ace/OS.i (cond_wait,cond_timedwait): Fixed a missing return to
handle the case where we're using USYNC_PROCESS for the external
mutexes.
- * ace/OS: Removed the waiters_lock_ mutex from the ACE_cond_t
- implementation. This is unnecessary (and broken) since we've
- got to use the external_mutex to serialize access to the
- waiters_ count consistently. Thanks to Patrick J. McNerthney
+ * ace/OS: Made the use of the waiters_lock_ mutex consistent in
+ the ACE_cond_t implementation. This was broken since we used
+ the external_mutex to serialize access to the waiters_ count
+ inconsistently. Thanks to Patrick J. McNerthney
<pat@thememedia.com> for reporting this very subtle bug.
Sun Dec 14 12:29:26 1997 Nanbor Wang <nw1@merengue.cs.wustl.edu>
diff --git a/ace/OS.h b/ace/OS.h
index 88314eecd76..448a92ac58b 100644
--- a/ace/OS.h
+++ b/ace/OS.h
@@ -1576,6 +1576,9 @@ protected:
long waiters_;
// Number of waiting threads.
+ ACE_thread_mutex_t waiters_lock_;
+ // Serialize access to the waiters count.
+
ACE_sema_t sema_;
// Queue up threads waiting for the condition to become signaled.
diff --git a/ace/OS.i b/ace/OS.i
index ef74f736ccb..30ff4a6f01e 100644
--- a/ace/OS.i
+++ b/ace/OS.i
@@ -2328,6 +2328,7 @@ ACE_OS::cond_destroy (ACE_cond_t *cv)
#elif defined (VXWORKS)
ACE_OS::sema_destroy (&cv->waiters_done_);
#endif /* VXWORKS */
+ ACE_OS::thread_mutex_destroy (&cv->waiters_lock_);
return ACE_OS::sema_destroy (&cv->sema_);
#else
ACE_UNUSED_ARG (cv);
@@ -2346,6 +2347,8 @@ ACE_OS::cond_init (ACE_cond_t *cv, int type, LPCTSTR name, void *arg)
int result = 0;
if (ACE_OS::sema_init (&cv->sema_, 0, type, name, arg) == -1)
result = -1;
+ else if (ACE_OS::thread_mutex_init (&cv->waiters_lock_) == -1)
+ result = -1;
#if defined (VXWORKS)
else if (ACE_OS::sema_init (&cv->waiters_done_, 0, type) == -1)
#else
@@ -2426,9 +2429,10 @@ ACE_OS::cond_wait (ACE_cond_t *cv,
{
// ACE_TRACE ("ACE_OS::cond_wait");
#if defined (ACE_HAS_THREADS)
- // It's ok to increment this because the <external_mutex> must be
- // locked by the caller.
+ // Prevent race conditions on the <waiters_> count.
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
cv->waiters_++;
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
int result = 0;
@@ -2455,8 +2459,7 @@ ACE_OS::cond_wait (ACE_cond_t *cv,
}
// Reacquire lock to avoid race conditions on the <waiters_> count.
- if (ACE_OS::mutex_lock (external_mutex) != 0)
- return -1;
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
// We're ready to return, so there's one less waiter.
cv->waiters_--;
@@ -2465,7 +2468,7 @@ ACE_OS::cond_wait (ACE_cond_t *cv,
// Release the lock so that other collaborating threads can make
// progress.
- ACE_OS::mutex_unlock (external_mutex);
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
if (result == -1)
// Bad things happened, so let's just return below.
@@ -2526,9 +2529,10 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv,
return ACE_OS::cond_wait (cv, external_mutex);
#if defined (ACE_HAS_WTHREADS) || defined (VXWORKS)
- // It's ok to increment this because the <external_mutex> must be
- // locked by the caller.
+ // Prevent race conditions on the <waiters_> count.
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
cv->waiters_++;
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
int result = 0;
int error = 0;
@@ -2583,14 +2587,12 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv,
}
// Reacquire lock to avoid race conditions.
- if (ACE_OS::mutex_lock (external_mutex) != 0)
- return -1;
-
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
cv->waiters_--;
int last_waiter = cv->was_broadcast_ && cv->waiters_ == 0;
- ACE_OS::mutex_unlock (external_mutex);
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
#if defined (ACE_WIN32)
if (result != WAIT_OBJECT_0)
@@ -2678,9 +2680,10 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv,
if (timeout == 0)
return ACE_OS::cond_wait (cv, external_mutex);
- // It's ok to increment this because the <external_mutex> must be
- // locked by the caller.
+ // Prevent race conditions on the <waiters_> count.
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
cv->waiters_++;
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
int result = 0;
int error = 0;
@@ -2714,14 +2717,13 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv,
result = ::WaitForSingleObject (cv->sema_, msec_timeout);
// Reacquire lock to avoid race conditions.
- if (ACE_OS::thread_mutex_lock (external_mutex) != 0)
- return -1;
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
cv->waiters_--;
int last_waiter = cv->was_broadcast_ && cv->waiters_ == 0;
- ACE_OS::thread_mutex_unlock (external_mutex);
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
if (result != WAIT_OBJECT_0)
{
@@ -2756,9 +2758,9 @@ ACE_OS::cond_wait (ACE_cond_t *cv,
{
// ACE_TRACE ("ACE_OS::cond_wait");
#if defined (ACE_HAS_THREADS)
- // It's ok to increment this because the <external_mutex> must be
- // locked by the caller.
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
cv->waiters_++;
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
int result = 0;
int error = 0;
@@ -2775,13 +2777,13 @@ ACE_OS::cond_wait (ACE_cond_t *cv,
result = ::WaitForSingleObject (cv->sema_, INFINITE);
// Reacquire lock to avoid race conditions.
- if (ACE_OS::thread_mutex_lock (external_mutex) != 0)
- return -1;
+ ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
+
cv->waiters_--;
int last_waiter = cv->was_broadcast_ && cv->waiters_ == 0;
- ACE_OS::thread_mutex_unlock (external_mutex);
+ ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);
if (result != WAIT_OBJECT_0)
{