summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2002-11-06 23:57:57 +0000
committerSteve Huston <shuston@riverace.com>2002-11-06 23:57:57 +0000
commit432b724f5bd378ed837d31e2c798a216a0a93f74 (patch)
tree45835a1fffe7850b50f65197e57b227818a2bda7
parentb547f7aa1fa95c3c0444ed7dea995a3f9636cca8 (diff)
downloadATCD-432b724f5bd378ed837d31e2c798a216a0a93f74.tar.gz
ChangeLogTag:Wed Nov 6 18:55:22 2002 Steve Huston <shuston@riverace.com>
-rw-r--r--ChangeLog14
-rw-r--r--ChangeLogs/ChangeLog-03a14
-rw-r--r--ace/OS.h9
-rw-r--r--ace/OS.i35
-rw-r--r--tests/Recursive_Condition_Test.cpp3
5 files changed, 54 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index a9450ba806e..553b206e45d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Wed Nov 6 18:55:22 2002 Steve Huston <shuston@riverace.com>
+
+ * ace/OS.{h i} (recursive_mutex_cond_unlock,
+ recursive_mutex_cond_relock): For Windows, don't try to save/restore
+ CRITICAL_SECTION members individually - there are undocumented
+ details at work there. Instead, release and acquire the mutex
+ one fewer times than the recursion count, letting Windows take
+ care of its internals. Fixes the hung Recursive_Condition_Test on
+ Windows. This also neatly removes the WinCE conditional code in
+ this area.
+
+ * tests/Recursive_Condition_Test.cpp: Fix a const error that gcc
+ pointed out.
+
Wed Nov 6 11:12:28 2002 Steve Huston <shuston@riverace.com>
* tests/Recursive_Condition_Test.cpp: Replaced ACE_TRACE with
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index a9450ba806e..553b206e45d 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,3 +1,17 @@
+Wed Nov 6 18:55:22 2002 Steve Huston <shuston@riverace.com>
+
+ * ace/OS.{h i} (recursive_mutex_cond_unlock,
+ recursive_mutex_cond_relock): For Windows, don't try to save/restore
+ CRITICAL_SECTION members individually - there are undocumented
+ details at work there. Instead, release and acquire the mutex
+ one fewer times than the recursion count, letting Windows take
+ care of its internals. Fixes the hung Recursive_Condition_Test on
+ Windows. This also neatly removes the WinCE conditional code in
+ this area.
+
+ * tests/Recursive_Condition_Test.cpp: Fix a const error that gcc
+ pointed out.
+
Wed Nov 6 11:12:28 2002 Steve Huston <shuston@riverace.com>
* tests/Recursive_Condition_Test.cpp: Replaced ACE_TRACE with
diff --git a/ace/OS.h b/ace/OS.h
index 96559481a37..9cfca067d33 100644
--- a/ace/OS.h
+++ b/ace/OS.h
@@ -2154,13 +2154,12 @@ typedef ACE_thread_mutex_t ACE_recursive_thread_mutex_t;
# if defined (ACE_WIN32)
// Windows has recursive mutexes, but doesn't have condition variables,
// so there's no built-in support for this. Thus, the condition-related
-// save/restore is handled in ACE.
+// unlock/relock is augmented in ACE.
struct ACE_recursive_mutex_state
{
- // On windows the mutex is a CRITICAL_SECTION, and these members
- // match those in the CRITICAL_SECTION struct.
- LONG lock_count_;
- LONG recursion_count_;
+ // On Windows the augmented processing is simply unlocking/relocking
+ // the recursive locks - the condition handles a single lock ok.
+ LONG relock_count_;
};
# else
// No need for special handling; just need a type for method signatures.
diff --git a/ace/OS.i b/ace/OS.i
index 46e2534ecae..255ede59013 100644
--- a/ace/OS.i
+++ b/ace/OS.i
@@ -2631,16 +2631,19 @@ ACE_OS::recursive_mutex_cond_unlock (ACE_recursive_thread_mutex_t *m,
// does not integrate them into a condition variable.
# if defined (ACE_WIN32)
// For Windows, the OS takes care of the mutex and its recursion. We just
- // need to save the nesting count and reduce it so that we can release
- // the mutex with the condition. When we reacquire it, reset the counts
- // to match the conditions before the wait occurred so that this thread
- // does all of its acquires and releases correctly.
- state.lock_count_ = m->LockCount;
- m->LockCount = 0;
-# if !defined (_WIN32_WCE) || (_WIN32_WCE >= 400) /* Windows and CE.NET */
- state.recursion_count_ = m->RecursionCount;
- m->RecursionCount = 1;
-# endif /* _WIN32_WCE >= 400 */
+ // need to release the lock one fewer times than this thread has acquired
+ // it. Remember how many times, and reacquire it that many more times when
+ // the condition is signaled.
+ state.relock_count_ = 0;
+ while (m->LockCount > 0)
+ {
+ // This may fail if the current thread doesn't own the mutex. If it
+ // does fail, it'll be on the first try, so don't worry about resetting
+ // the state.
+ if (ACE_OS::recursive_mutex_unlock (m) == -1)
+ return -1;
+ ++state.relock_count_;
+ }
# endif /* ACE_WIN32 */
return 0;
# else /* ACE_HAS_RECURSIVE_MUTEXES */
@@ -2710,12 +2713,14 @@ ACE_OS::recursive_mutex_cond_relock (ACE_recursive_thread_mutex_t *m,
// Windows need special handling since it has recursive mutexes, but
// does not integrate them into a condition variable.
// On entry, the OS has already reacquired the lock for us. Just
- // restore the counts to what they were before waiting on the condition.
+ // reacquire it the proper number of times so the recursion is the same as
+ // before waiting on the condition.
# if defined (ACE_WIN32)
- m->LockCount = state.lock_count_;
-# if !defined (_WIN32_WCE) || (_WIN32_WCE >= 400) /* Windows and CE.NET */
- m->RecursionCount = state.recursion_count_;
-# endif /* _WIN32_WCE >= 400 */
+ while (state.relock_count_ > 0)
+ {
+ ACE_OS::recursive_mutex_lock (m);
+ --state.relock_count_;
+ }
return;
# endif /* ACE_WIN32 */
# else
diff --git a/tests/Recursive_Condition_Test.cpp b/tests/Recursive_Condition_Test.cpp
index 39639fca0a7..6fa0eb56245 100644
--- a/tests/Recursive_Condition_Test.cpp
+++ b/tests/Recursive_Condition_Test.cpp
@@ -46,8 +46,9 @@ public:
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) Test_Handler::handle_timeout\n")));
++this->nr_expirations_;
+ void *nc_arg = ACE_const_cast (void *, arg);
Thread_Timer_Queue *timer_queue =
- ACE_reinterpret_cast (Thread_Timer_Queue *, arg);
+ ACE_reinterpret_cast (Thread_Timer_Queue *, nc_arg);
ACE_Time_Value timeout = ACE_OS::gettimeofday () + ACE_Time_Value (1, 0);