diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-08-26 17:05:53 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-08-26 17:05:53 +0000 |
commit | d55ddf54f698f4e9399099918986c0844a72e9ad (patch) | |
tree | ab3830ba81eb543b8ee793c715e4daf58c7d8293 | |
parent | 2ab9e5017178750e4b59f0d0693311baab85dd30 (diff) | |
download | ATCD-d55ddf54f698f4e9399099918986c0844a72e9ad.tar.gz |
Changes to deal with destruction of thread pools.
-rw-r--r-- | TAO/tao/Default_Thread_Lane_Resources_Manager.cpp | 33 | ||||
-rw-r--r-- | TAO/tao/Default_Thread_Lane_Resources_Manager.h | 4 | ||||
-rw-r--r-- | TAO/tao/ORB_Core.cpp | 5 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp | 112 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h | 8 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/Thread_Pool.cpp | 75 | ||||
-rw-r--r-- | TAO/tao/RTCORBA/Thread_Pool.h | 24 | ||||
-rw-r--r-- | TAO/tao/Thread_Lane_Resources.cpp | 29 | ||||
-rw-r--r-- | TAO/tao/Thread_Lane_Resources.h | 3 | ||||
-rw-r--r-- | TAO/tao/Thread_Lane_Resources_Manager.h | 4 | ||||
-rw-r--r-- | TAO/tests/RTCORBA/Destroy_Thread_Pool/Destroy_Thread_Pool.cpp | 9 | ||||
-rw-r--r-- | TAO/threadpool-changes | 13 |
12 files changed, 161 insertions, 158 deletions
diff --git a/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp b/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp index aea1e6a363a..7a9bf435299 100644 --- a/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp +++ b/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp @@ -80,37 +80,10 @@ TAO_Default_Thread_Lane_Resources_Manager::default_lane_resources (void) return this->lane_resources (); } -int -TAO_Default_Thread_Lane_Resources_Manager::shutdown_all_reactors (CORBA_Environment &) +void +TAO_Default_Thread_Lane_Resources_Manager::shutdown_reactor (void) { - // Get to the leader/follower class. - TAO_Leader_Follower &leader_follower = - this->lane_resources_->leader_follower (); - - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - ace_mon, - leader_follower.lock (), - -1); - - // Wakeup all the threads waiting blocked in the event loop, this - // does not guarantee that they will all go away, but reduces the - // load on the POA.... - ACE_Reactor *reactor = - leader_follower.reactor (); - - reactor->wakeup_all_threads (); - - // If there are some client threads running we have to wait until - // they finish, when the last one does it will shutdown the reactor - // for us. Meanwhile no new requests will be accepted because the - // POA will not process them. - if (!leader_follower.has_clients ()) - { - // Wake up all waiting threads in the reactor. - reactor->end_reactor_event_loop (); - } - - return 0; + this->lane_resources_->shutdown_reactor (); } TAO_Thread_Lane_Resources_Manager * diff --git a/TAO/tao/Default_Thread_Lane_Resources_Manager.h b/TAO/tao/Default_Thread_Lane_Resources_Manager.h index 95f3ebdaee2..06307d35b89 100644 --- a/TAO/tao/Default_Thread_Lane_Resources_Manager.h +++ b/TAO/tao/Default_Thread_Lane_Resources_Manager.h @@ -46,8 +46,8 @@ public: /// Open default resources. int open_default_resources (CORBA_Environment &ACE_TRY_ENV); - /// Shutdown all reactors. - int shutdown_all_reactors (CORBA_Environment &ACE_TRY_ENV); + /// Shutdown reactor. + void shutdown_reactor (void); /// @name Accessors // @{ diff --git a/TAO/tao/ORB_Core.cpp b/TAO/tao/ORB_Core.cpp index 26d045a06c1..28e9da2aa40 100644 --- a/TAO/tao/ORB_Core.cpp +++ b/TAO/tao/ORB_Core.cpp @@ -1838,9 +1838,8 @@ TAO_ORB_Core::shutdown (CORBA::Boolean wait_for_completion, // Set the shutdown flag this->has_shutdown_ = 1; - // Shutdown all the reactors.... - this->thread_lane_resources_manager ().shutdown_all_reactors (ACE_TRY_ENV); - ACE_CHECK; + // Shutdown reactor. + this->thread_lane_resources_manager ().shutdown_reactor (); // Grab the thread manager ACE_Thread_Manager *tm = this->thr_mgr (); diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp index c0368f6257a..b957b6a9241 100644 --- a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp @@ -78,30 +78,18 @@ TAO_RT_Thread_Lane_Resources_Manager::finalize (void) // Finalize default resources. this->default_lane_resources_->finalize (); - TAO_Thread_Pool_Manager::THREAD_POOLS &thread_pools = - this->tp_manager_->thread_pools (); - - // Go through all the lanes and finalize their resources. - for (TAO_Thread_Pool_Manager::THREAD_POOLS::iterator pool_iterator = - thread_pools.begin (); - pool_iterator != thread_pools.end (); - ++pool_iterator) - { - TAO_Thread_Lane **lanes = - (*pool_iterator).int_id_->lanes (); - CORBA::ULong number_of_lanes = - (*pool_iterator).int_id_->number_of_lanes (); - - for (CORBA::ULong lane = 0; - lane != number_of_lanes; - ++lane) - { - TAO_Thread_Lane_Resources &lane_resources = - lanes[lane]->resources (); - - lane_resources.finalize (); - } - } + // Finalize resources managed by the thread-pool manager. + this->tp_manager_->finalize (); +} + +void +TAO_RT_Thread_Lane_Resources_Manager::shutdown_reactor (void) +{ + // Shutdown default reactors. + this->default_lane_resources_->shutdown_reactor (); + + // Shutdown reactors managed by the thread-pool manager. + this->tp_manager_->shutdown_reactor (); } TAO_Thread_Lane_Resources & @@ -129,82 +117,6 @@ TAO_RT_Thread_Lane_Resources_Manager::default_lane_resources (void) return *this->default_lane_resources_; } -int -TAO_RT_Thread_Lane_Resources_Manager::shutdown_reactors (TAO_Thread_Lane_Resources &lane_resources, - CORBA_Environment &) -{ - TAO_Leader_Follower &leader_follower = - lane_resources.leader_follower (); - - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - ace_mon, - leader_follower.lock (), - -1); - - // Wakeup all the threads waiting blocked in the event loop, this - // does not guarantee that they will all go away, but reduces the - // load on the POA.... - ACE_Reactor *reactor = - leader_follower.reactor (); - - reactor->wakeup_all_threads (); - - // If there are some client threads running we have to wait until - // they finish, when the last one does it will shutdown the reactor - // for us. Meanwhile no new requests will be accepted because the - // POA will not process them. - if (!leader_follower.has_clients ()) - { - // Wake up all waiting threads in the reactor. - reactor->end_reactor_event_loop (); - } - - return 0; -} - -int -TAO_RT_Thread_Lane_Resources_Manager::shutdown_all_reactors (CORBA_Environment &ACE_TRY_ENV) -{ - // Shutdown default reactors. - int result = - this->shutdown_reactors (*this->default_lane_resources_, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - if (result != 0) - return result; - - TAO_Thread_Pool_Manager::THREAD_POOLS &thread_pools = - this->tp_manager_->thread_pools (); - - // Shutdown reactors in all the lanes. - for (TAO_Thread_Pool_Manager::THREAD_POOLS::iterator pool_iterator = - thread_pools.begin (); - pool_iterator != thread_pools.end (); - ++pool_iterator) - { - TAO_Thread_Lane **lanes = - (*pool_iterator).int_id_->lanes (); - CORBA::ULong number_of_lanes = - (*pool_iterator).int_id_->number_of_lanes (); - - for (CORBA::ULong lane = 0; - lane != number_of_lanes && result == 0; - ++lane) - { - result = - this->shutdown_reactors (lanes[lane]->resources (), - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - } - } - - if (result != 0) - return result; - - return 0; -} - TAO_Thread_Pool_Manager & TAO_RT_Thread_Lane_Resources_Manager::tp_manager (void) { diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h index c71e22b9e60..4e3fda3ee90 100644 --- a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h @@ -49,8 +49,8 @@ public: /// Open default resources. int open_default_resources (CORBA_Environment &ACE_TRY_ENV); - /// Shutdown all reactors. - int shutdown_all_reactors (CORBA_Environment &ACE_TRY_ENV); + /// Shutdown reactor. + void shutdown_reactor (void); /// @name Accessors // @{ @@ -65,10 +65,6 @@ public: protected: - /// Shutdown reactors. - int shutdown_reactors (TAO_Thread_Lane_Resources &lane_resources, - CORBA_Environment &ACE_TRY_ENV); - /// Mutual exclusion for calling open. TAO_SYNCH_MUTEX open_lock_; diff --git a/TAO/tao/RTCORBA/Thread_Pool.cpp b/TAO/tao/RTCORBA/Thread_Pool.cpp index ebae71b2f2a..4616ca6817d 100644 --- a/TAO/tao/RTCORBA/Thread_Pool.cpp +++ b/TAO/tao/RTCORBA/Thread_Pool.cpp @@ -11,6 +11,7 @@ ACE_RCSID(tao, Thread_Pool, "$Id$") #include "tao/Transport_Cache_Manager.h" #include "tao/debug.h" #include "tao/RTCORBA/Priority_Mapping_Manager.h" +#include "tao/Leader_Follower.h" #if !defined (__ACE_INLINE__) # include "Thread_Pool.i" @@ -52,6 +53,9 @@ TAO_Thread_Pool_Threads::svc (void) // No point propagating this exception. Print it out. ACE_ERROR ((LM_ERROR, "orb->run() raised exception for thread %t\n")); + + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + ""); } ACE_ENDTRY; @@ -153,12 +157,24 @@ TAO_Thread_Lane::~TAO_Thread_Lane (void) } void -TAO_Thread_Lane::fini (void) +TAO_Thread_Lane::finalize (void) { // Finalize resources. this->resources_.finalize (); } +void +TAO_Thread_Lane::shutdown_reactor (void) +{ + this->resources_.shutdown_reactor (); +} + +void +TAO_Thread_Lane::wait (void) +{ + this->threads_.wait (); +} + int TAO_Thread_Lane::create_static_threads (void) { @@ -364,13 +380,33 @@ TAO_Thread_Pool::~TAO_Thread_Pool (void) } void -TAO_Thread_Pool::fini (void) +TAO_Thread_Pool::finalize (void) { // Finalize all the lanes. for (CORBA::ULong i = 0; i != this->number_of_lanes_; ++i) - this->lanes_[i]->fini (); + this->lanes_[i]->finalize (); +} + +void +TAO_Thread_Pool::shutdown_reactor (void) +{ + // Finalize all the lanes. + for (CORBA::ULong i = 0; + i != this->number_of_lanes_; + ++i) + this->lanes_[i]->shutdown_reactor (); +} + +void +TAO_Thread_Pool::wait (void) +{ + // Finalize all the lanes. + for (CORBA::ULong i = 0; + i != this->number_of_lanes_; + ++i) + this->lanes_[i]->wait (); } int @@ -481,13 +517,33 @@ TAO_Thread_Pool_Manager::~TAO_Thread_Pool_Manager (void) } void -TAO_Thread_Pool_Manager::fini (void) +TAO_Thread_Pool_Manager::finalize (void) +{ + // Finalize all the pools. + for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin (); + iterator != this->thread_pools_.end (); + ++iterator) + (*iterator).int_id_->finalize (); +} + +void +TAO_Thread_Pool_Manager::shutdown_reactor (void) +{ + // Finalize all the pools. + for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin (); + iterator != this->thread_pools_.end (); + ++iterator) + (*iterator).int_id_->shutdown_reactor (); +} + +void +TAO_Thread_Pool_Manager::wait (void) { // Finalize all the pools. for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin (); iterator != this->thread_pools_.end (); ++iterator) - (*iterator).int_id_->fini (); + (*iterator).int_id_->wait (); } RTCORBA::ThreadpoolId @@ -670,6 +726,15 @@ TAO_Thread_Pool_Manager::destroy_threadpool_i (RTCORBA::ThreadpoolId thread_pool if (result != 0) ACE_THROW (RTCORBA::RTORB::InvalidThreadpool ()); + // Shutdown reactor. + thread_pool->shutdown_reactor (); + + // Wait for the threads. + thread_pool->wait (); + + // Finalize resources. + thread_pool->finalize (); + // Delete the thread pool. delete thread_pool; } diff --git a/TAO/tao/RTCORBA/Thread_Pool.h b/TAO/tao/RTCORBA/Thread_Pool.h index f636d570fec..f0584ba6a2b 100644 --- a/TAO/tao/RTCORBA/Thread_Pool.h +++ b/TAO/tao/RTCORBA/Thread_Pool.h @@ -88,7 +88,13 @@ public: void open (CORBA::Environment &ACE_TRY_ENV); /// Finalize the resources. - void fini (void); + void finalize (void); + + /// Shutdown the reactor. + void shutdown_reactor (void); + + /// Wait for threads to exit. + void wait (void); /// Create the static threads - only called once. int create_static_threads (void); @@ -181,7 +187,13 @@ public: void open (CORBA::Environment &ACE_TRY_ENV); /// Finalize the resources. - void fini (void); + void finalize (void); + + /// Shutdown the reactor. + void shutdown_reactor (void); + + /// Wait for threads to exit. + void wait (void); /// Create the static threads - only called once. int create_static_threads (void); @@ -243,7 +255,13 @@ public: ~TAO_Thread_Pool_Manager (void); /// Finalize the resources. - void fini (void); + void finalize (void); + + /// Shutdown the reactor. + void shutdown_reactor (void); + + /// Wait for threads to exit. + void wait (void); /// Create a threadpool without lanes. RTCORBA::ThreadpoolId diff --git a/TAO/tao/Thread_Lane_Resources.cpp b/TAO/tao/Thread_Lane_Resources.cpp index dadbd317a79..cf90efa4619 100644 --- a/TAO/tao/Thread_Lane_Resources.cpp +++ b/TAO/tao/Thread_Lane_Resources.cpp @@ -146,3 +146,32 @@ TAO_Thread_Lane_Resources::finalize (void) delete this->transport_cache_; delete this->leader_follower_; } + +void +TAO_Thread_Lane_Resources::shutdown_reactor (void) +{ + TAO_Leader_Follower &leader_follower = + this->leader_follower (); + + ACE_GUARD (TAO_SYNCH_MUTEX, + ace_mon, + leader_follower.lock ()); + + // Wakeup all the threads waiting blocked in the event loop, this + // does not guarantee that they will all go away, but reduces the + // load on the POA.... + ACE_Reactor *reactor = + leader_follower.reactor (); + + reactor->wakeup_all_threads (); + + // If there are some client threads running we have to wait until + // they finish, when the last one does it will shutdown the reactor + // for us. Meanwhile no new requests will be accepted because the + // POA will not process them. + if (!leader_follower.has_clients ()) + { + // Wake up all waiting threads in the reactor. + reactor->end_reactor_event_loop (); + } +} diff --git a/TAO/tao/Thread_Lane_Resources.h b/TAO/tao/Thread_Lane_Resources.h index 2b89c49c6cd..54c887e8627 100644 --- a/TAO/tao/Thread_Lane_Resources.h +++ b/TAO/tao/Thread_Lane_Resources.h @@ -51,6 +51,9 @@ public: /// Finalize resources. void finalize (void); + /// Shutdown the reactor. + void shutdown_reactor (void); + /// @name Accessors // @{ diff --git a/TAO/tao/Thread_Lane_Resources_Manager.h b/TAO/tao/Thread_Lane_Resources_Manager.h index ef5349723ca..66e125af9d3 100644 --- a/TAO/tao/Thread_Lane_Resources_Manager.h +++ b/TAO/tao/Thread_Lane_Resources_Manager.h @@ -49,8 +49,8 @@ public: /// Open default resources. virtual int open_default_resources (CORBA_Environment &ACE_TRY_ENV) = 0; - /// Shutdown all reactors. - virtual int shutdown_all_reactors (CORBA_Environment &ACE_TRY_ENV) = 0; + /// Shutdown reactor. + virtual void shutdown_reactor (void) = 0; /// @name Accessors // @{ diff --git a/TAO/tests/RTCORBA/Destroy_Thread_Pool/Destroy_Thread_Pool.cpp b/TAO/tests/RTCORBA/Destroy_Thread_Pool/Destroy_Thread_Pool.cpp index 1d1974b1340..e151e684a31 100644 --- a/TAO/tests/RTCORBA/Destroy_Thread_Pool/Destroy_Thread_Pool.cpp +++ b/TAO/tests/RTCORBA/Destroy_Thread_Pool/Destroy_Thread_Pool.cpp @@ -40,7 +40,6 @@ parse_args (int argc, char *argv[]) -1); } - // Indicates sucessful parsing of the command line return 0; } @@ -127,8 +126,8 @@ main (int argc, char *argv[]) ACE_TRY_ENV); ACE_TRY_CHECK; - //rt_orb->destroy_threadpool (id, - //ACE_TRY_ENV); + rt_orb->destroy_threadpool (id, + ACE_TRY_ENV); ACE_TRY_CHECK; id = @@ -136,8 +135,8 @@ main (int argc, char *argv[]) ACE_TRY_ENV); ACE_TRY_CHECK; - //rt_orb->destroy_threadpool (id, - //ACE_TRY_ENV); + rt_orb->destroy_threadpool (id, + ACE_TRY_ENV); ACE_TRY_CHECK; } diff --git a/TAO/threadpool-changes b/TAO/threadpool-changes index a989a4f1f00..6784f27b281 100644 --- a/TAO/threadpool-changes +++ b/TAO/threadpool-changes @@ -194,6 +194,11 @@ Fri Aug 24 18:08:37 2001 Irfan Pyarali <irfan@cs.wustl.edu> - (native_priority): Each lane remembers its native priority in addition to its CORBA priority. + - (destroy_threadpool_i): We now shutdown the reactors in + the thread pool, wait for the threads in the pool to exit, + finalize the resources in the pool, and only then delete + the thread pool. + * tao/RTCORBA/RT_Protocols_Hooks.cpp (set_default_server_protocol_policy): Don't include all the protocols that the ORB knows about in the default server @@ -734,6 +739,10 @@ Fri Aug 24 18:08:37 2001 Irfan Pyarali <irfan@cs.wustl.edu> - README: Updated to reflect changes in the test. + * tests/RTCORBA/Destroy_Thread_Pool: New test added that tests + the creation and destruction of thread pools (with and + without lanes). + * tests/RTCORBA/Banded_Connections: - server.cpp: @@ -849,8 +858,8 @@ Fri Aug 24 18:08:37 2001 Irfan Pyarali <irfan@cs.wustl.edu> * tests/RTCORBA/Makefile: * tests/RTCORBA/Makefile.bor: - Added new tests ORB_init, Policy_Combinations, and - Linear_Priority. + Added new tests ORB_init, Policy_Combinations, + Destroy_Thread_Pool, and Linear_Priority. * tests/RTCORBA/Banded_Connections/Makefile: * tests/RTCORBA/Banded_Connections/client.bor: |