diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-07-10 02:51:24 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-07-10 02:51:24 +0000 |
commit | bf7463f6579ca86144bf2bb42e66658ed09586d5 (patch) | |
tree | 82075b7dae6cf27477a5d7b4256eb42957e567c1 /tests | |
parent | 336e16cf0d09a2d05e15a810cdda687a2dd23b2f (diff) | |
download | ATCD-bf7463f6579ca86144bf2bb42e66658ed09586d5.tar.gz |
ChangeLogTag: Wed Jul 09 22:48:48 2003 Irfan Pyarali <irfan@oomworks.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Thread_Pool_Reactor_Resume_Test.cpp | 57 | ||||
-rw-r--r-- | tests/Thread_Pool_Reactor_Resume_Test.h | 14 |
2 files changed, 25 insertions, 46 deletions
diff --git a/tests/Thread_Pool_Reactor_Resume_Test.cpp b/tests/Thread_Pool_Reactor_Resume_Test.cpp index c8b5d235e28..711457aecd7 100644 --- a/tests/Thread_Pool_Reactor_Resume_Test.cpp +++ b/tests/Thread_Pool_Reactor_Resume_Test.cpp @@ -119,38 +119,48 @@ 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), - ref_count_ (1), - refcount_lock_ (0) + nr_msgs_rcvd_(0) { + // Enable reference counting. + this->reference_counting_policy ().value + (ACE_Event_Handler::Reference_Counting_Policy::ENABLED); + // Make sure we use TP_Reactor with this class (that's the whole // point, right?) this->reactor (ACE_Reactor::instance ()); +} + +int +Request_Handler::open (void *arg) +{ + // Open base class. + int result = + ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>::open (arg); - // Create the lock - ACE_NEW (refcount_lock_, - ACE_Lock_Adapter<ACE_SYNCH_MUTEX>); + // Return on error. + if (result == -1) + return -1; + + // Else we have successfully registered with the Reactor. Give our + // ownership to the Reactor. + this->remove_reference (); + + // Return result. + return result; } 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) { @@ -158,14 +168,12 @@ Request_Handler::handle_input (ACE_HANDLE fd) ACE_TCHAR len = 0; ssize_t result = this->peer ().recv (&len, sizeof (ACE_TCHAR)); - if (result > 0 && this->peer ().recv_n (buffer, len * sizeof (ACE_TCHAR)) == ACE_static_cast (ssize_t, len * sizeof (ACE_TCHAR))) { ++this->nr_msgs_rcvd_; - // Now the handle_input method has done what it can do, namely // read the data from the socket we can just resume the handler // at this point @@ -176,13 +184,11 @@ 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; } else { - ACE_DEBUG ((LM_DEBUG, "(%t) Errno is %d and result is %d\n", errno, result)); @@ -206,27 +212,10 @@ Request_Handler::handle_close (ACE_HANDLE fd, ACE_Reactor_Mask) this, cli_req_no, this->nr_msgs_rcvd_)); - 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 (ACE_Reactor *) { diff --git a/tests/Thread_Pool_Reactor_Resume_Test.h b/tests/Thread_Pool_Reactor_Resume_Test.h index 09578762eb9..f39a06addfc 100644 --- a/tests/Thread_Pool_Reactor_Resume_Test.h +++ b/tests/Thread_Pool_Reactor_Resume_Test.h @@ -43,25 +43,15 @@ public: /// Dtor.. ~Request_Handler (void); + virtual int open (void * = 0); + protected: virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE); virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask = 0); 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 */ |