summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbala <balanatarajan@users.noreply.github.com>2001-07-25 13:10:19 +0000
committerbala <balanatarajan@users.noreply.github.com>2001-07-25 13:10:19 +0000
commit2f66c0a890d206140d13d4171426f50b94b5908a (patch)
tree058d1fb84a625d046fe56d39eae51401909fe06b
parentf036b3a58731d14c3010ed417d65572f0728100e (diff)
downloadATCD-2f66c0a890d206140d13d4171426f50b94b5908a.tar.gz
ChangeLogTag: Wed Jul 25 08:05:45 2001 Balachandran Natarajan <bala@cs.wustl.edu>
-rw-r--r--ChangeLog9
-rw-r--r--ChangeLogs/ChangeLog-02a9
-rw-r--r--ChangeLogs/ChangeLog-03a9
-rw-r--r--tests/Thread_Pool_Reactor_Resume_Test.cpp43
-rw-r--r--tests/Thread_Pool_Reactor_Resume_Test.h18
5 files changed, 84 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index d9f429a1e66..cddc9ae9cb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Jul 25 08:05:45 2001 Balachandran Natarajan <bala@cs.wustl.edu>
+
+ * tests/Thread_Pool_Reactor_Resume_Test.h:
+ * tests/Thread_Pool_Reactor_Resume_Test.cpp: Fixed a subtle race
+ condition. This hardly showed up in many of our daily
+ builds. The race condition had to be fixed to show the users of
+ the cautious approach that one needs to take if they are
+ resuming the handle in the application itself.
+
Tue Jul 24 16:41:57 2001 Joe Hoffert <joeh@cs.wustl.edu>
* ace/Thread_Manager.cpp :
diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a
index d9f429a1e66..cddc9ae9cb0 100644
--- a/ChangeLogs/ChangeLog-02a
+++ b/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,12 @@
+Wed Jul 25 08:05:45 2001 Balachandran Natarajan <bala@cs.wustl.edu>
+
+ * tests/Thread_Pool_Reactor_Resume_Test.h:
+ * tests/Thread_Pool_Reactor_Resume_Test.cpp: Fixed a subtle race
+ condition. This hardly showed up in many of our daily
+ builds. The race condition had to be fixed to show the users of
+ the cautious approach that one needs to take if they are
+ resuming the handle in the application itself.
+
Tue Jul 24 16:41:57 2001 Joe Hoffert <joeh@cs.wustl.edu>
* ace/Thread_Manager.cpp :
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index d9f429a1e66..cddc9ae9cb0 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,3 +1,12 @@
+Wed Jul 25 08:05:45 2001 Balachandran Natarajan <bala@cs.wustl.edu>
+
+ * tests/Thread_Pool_Reactor_Resume_Test.h:
+ * tests/Thread_Pool_Reactor_Resume_Test.cpp: Fixed a subtle race
+ condition. This hardly showed up in many of our daily
+ builds. The race condition had to be fixed to show the users of
+ the cautious approach that one needs to take if they are
+ resuming the handle in the application itself.
+
Tue Jul 24 16:41:57 2001 Joe Hoffert <joeh@cs.wustl.edu>
* ace/Thread_Manager.cpp :
diff --git a/tests/Thread_Pool_Reactor_Resume_Test.cpp b/tests/Thread_Pool_Reactor_Resume_Test.cpp
index 790d04a2117..27cfc54c34a 100644
--- a/tests/Thread_Pool_Reactor_Resume_Test.cpp
+++ b/tests/Thread_Pool_Reactor_Resume_Test.cpp
@@ -77,7 +77,6 @@ static size_t cli_req_no = ACE_MAX_THREADS ACE_LOAD_FACTOR;
// Delay before a thread sending the next request (in msec.)
static int req_delay = 50;
-
static void
parse_arg (int argc, ACE_TCHAR *argv[])
{
@@ -120,21 +119,37 @@ parse_arg (int argc, ACE_TCHAR *argv[])
Request_Handler::Request_Handler (ACE_Thread_Manager *thr_mgr)
: ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH> (thr_mgr),
- nr_msgs_rcvd_(0)
+ nr_msgs_rcvd_(0),
+ ref_count_ (1)
{
// Make sure we use TP_Reactor with this class (that's the whole
// point, right?)
this->reactor (ACE_Reactor::instance ());
+
+ // Create the lock
+ ACE_NEW (refcount_lock_,
+ ACE_Lock_Adapter<ACE_SYNCH_MUTEX>);
+}
+
+Request_Handler::~Request_Handler (void)
+{
+ delete this->refcount_lock_;
}
+
int
Request_Handler::resume_handler (void)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) resume_handler () called \n")));
+ this->_decr_ref_count ();
+
+ if (this->ref_count_ == 0)
+ this->destroy ();
return 1;
}
+
int
Request_Handler::handle_input (ACE_HANDLE fd)
{
@@ -160,6 +175,7 @@ Request_Handler::handle_input (ACE_HANDLE fd)
if (ACE_OS::strcmp (buffer, ACE_TEXT ("shutdown")) == 0)
ACE_Reactor::end_event_loop ();
+ this->_incr_ref_count ();
this->reactor ()->resume_handler (fd);
return 0;
}
@@ -189,10 +205,29 @@ Request_Handler::handle_close (ACE_HANDLE fd, ACE_Reactor_Mask)
this,
cli_req_no,
this->nr_msgs_rcvd_));
- this->destroy ();
+ this->_decr_ref_count ();
+
+ if (this->ref_count_ == 0)
+ this->destroy ();
return 0;
}
+void
+Request_Handler::_incr_ref_count (void)
+{
+ ACE_MT (ACE_GUARD (ACE_Lock, guard, *this->refcount_lock_));
+ ++this->ref_count_;
+}
+
+void
+Request_Handler::_decr_ref_count (void)
+{
+ ACE_MT (ACE_GUARD (ACE_Lock, guard, *this->refcount_lock_));
+ --this->ref_count_;
+}
+
+
+
static int
reactor_event_hook (void *)
{
@@ -357,6 +392,7 @@ template class ACE_Scheduling_Strategy<Request_Handler>;
template class ACE_Acceptor<Request_Handler, ACE_SOCK_ACCEPTOR>;
template class ACE_Strategy_Acceptor<Request_Handler, ACE_SOCK_ACCEPTOR>;
template class ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>;
+template class ACE_Lock_Adapter<ACE_SYNCH_MUTEX>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Accept_Strategy<Request_Handler, ACE_SOCK_ACCEPTOR>
#pragma instantiate ACE_Concurrency_Strategy<Request_Handler>
@@ -365,6 +401,7 @@ template class ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>;
#pragma instantiate ACE_Acceptor<Request_Handler, ACE_SOCK_ACCEPTOR>
#pragma instantiate ACE_Strategy_Acceptor<Request_Handler, ACE_SOCK_ACCEPTOR>
#pragma instantiate ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>
+#pragma instantiate ACE_Lock_Adapter<ACE_SYNCH_MUTEX>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
#else
diff --git a/tests/Thread_Pool_Reactor_Resume_Test.h b/tests/Thread_Pool_Reactor_Resume_Test.h
index 6824fa77f22..09578762eb9 100644
--- a/tests/Thread_Pool_Reactor_Resume_Test.h
+++ b/tests/Thread_Pool_Reactor_Resume_Test.h
@@ -36,8 +36,12 @@ class Request_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>
// = TITLE
// This class is the Svc_Handler used by <Acceptor>.
public:
+
+ /// The default constructor makes sure the right reactor is used.
Request_Handler (ACE_Thread_Manager *tm = 0);
- // The default constructor makes sure the right reactor is used.
+
+ /// Dtor..
+ ~Request_Handler (void);
protected:
virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
@@ -45,7 +49,19 @@ protected:
virtual int resume_handler (void);
private:
+ void _incr_ref_count (void);
+ void _decr_ref_count (void);
+
+private:
size_t nr_msgs_rcvd_;
+
+ /// Reference count of the number of threads using the handle. This
+ /// is needed to make sure that one thread doesnt delete the handle
+ /// when the other thread has just resumed the handle..
+ int ref_count_;
+
+ /// The lock for the ref count
+ ACE_Lock *refcount_lock_;
};
#endif /* ACE_TESTS_THREAD_POOL_REACTOR_RESUME_TEST_H */