From 2fe75c24fc4932f665a9ef7139846bc4a1c481c2 Mon Sep 17 00:00:00 2001 From: irfan Date: Tue, 31 Jul 2001 00:02:08 +0000 Subject: Moved around the Thread Pool Manager and RT service initialization... --- TAO/tao/RTCORBA/RT_ORB.cpp | 53 ++++++++++-------- TAO/tao/RTCORBA/RT_ORB.h | 6 +-- TAO/tao/RTCORBA/RT_ORBInitializer.cpp | 26 +++++---- .../RTCORBA/RT_Thread_Lane_Resources_Manager.cpp | 62 ++++++++++++++++------ TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h | 6 +++ 5 files changed, 104 insertions(+), 49 deletions(-) diff --git a/TAO/tao/RTCORBA/RT_ORB.cpp b/TAO/tao/RTCORBA/RT_ORB.cpp index ae402796759..8e04bb9c231 100644 --- a/TAO/tao/RTCORBA/RT_ORB.cpp +++ b/TAO/tao/RTCORBA/RT_ORB.cpp @@ -5,6 +5,8 @@ #include "RT_Mutex.h" #include "Priority_Mapping_Manager.h" #include "tao/ORB_Core.h" +#include "RTCORBA/Thread_Pool.h" +#include "RTCORBA/RT_Thread_Lane_Resources_Manager.h" #if ! defined (__ACE_INLINE__) #include "RT_ORB.i" @@ -71,12 +73,21 @@ TAO_RT_CORBA_Priority_Normalizer::normalize (CORBA::Short corba_priority, TAO_RT_ORB::TAO_RT_ORB (TAO_ORB_Core *orb_core) : orb_core_ (orb_core), mutex_mgr_ (), - tp_manager_ (*orb_core) + tp_manager_ (0) { TAO_RT_CORBA_Priority_Normalizer *corba_priority_normalizer = 0; ACE_NEW (corba_priority_normalizer, TAO_RT_CORBA_Priority_Normalizer (orb_core)); orb_core->corba_priority_normalizer (corba_priority_normalizer); + + TAO_Thread_Lane_Resources_Manager *thread_lane_resources_manager = + &this->orb_core_->thread_lane_resources_manager (); + + TAO_RT_Thread_Lane_Resources_Manager *rt_thread_lane_resources_manager = + (TAO_RT_Thread_Lane_Resources_Manager *) thread_lane_resources_manager; + + this->tp_manager_ = + &rt_thread_lane_resources_manager->tp_manager (); } TAO_RT_ORB::~TAO_RT_ORB (void) @@ -313,15 +324,15 @@ TAO_RT_ORB::create_threadpool (CORBA::ULong stacksize, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { - return this->tp_manager_.create_threadpool (stacksize, - static_threads, - dynamic_threads, - default_priority, - allow_request_buffering, - max_buffered_requests, - max_request_buffer_size, - 1, - ACE_TRY_ENV); + return this->tp_manager_->create_threadpool (stacksize, + static_threads, + dynamic_threads, + default_priority, + allow_request_buffering, + max_buffered_requests, + max_request_buffer_size, + 1, + ACE_TRY_ENV); } RTCORBA::ThreadpoolId @@ -334,14 +345,14 @@ TAO_RT_ORB::create_threadpool_with_lanes (CORBA::ULong stacksize, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { - return this->tp_manager_.create_threadpool_with_lanes (stacksize, - lanes, - allow_borrowing, - allow_request_buffering, - max_buffered_requests, - max_request_buffer_size, - 1, - ACE_TRY_ENV); + return this->tp_manager_->create_threadpool_with_lanes (stacksize, + lanes, + allow_borrowing, + allow_request_buffering, + max_buffered_requests, + max_request_buffer_size, + 1, + ACE_TRY_ENV); } void @@ -350,8 +361,8 @@ TAO_RT_ORB::destroy_threadpool (RTCORBA::ThreadpoolId threadpool, ACE_THROW_SPEC ((CORBA::SystemException, RTCORBA::RTORB::InvalidThreadpool)) { - this->tp_manager_.destroy_threadpool (threadpool, - ACE_TRY_ENV); + this->tp_manager_->destroy_threadpool (threadpool, + ACE_TRY_ENV); } RTCORBA::PriorityModelPolicy_ptr @@ -448,7 +459,7 @@ TAO_RT_ORB::create_client_protocol_policy (const RTCORBA::ProtocolList & protoco TAO_Thread_Pool_Manager & TAO_RT_ORB::tp_manager (void) { - return this->tp_manager_; + return *this->tp_manager_; } //////////////////////////////////////////////////////////////////////////////// diff --git a/TAO/tao/RTCORBA/RT_ORB.h b/TAO/tao/RTCORBA/RT_ORB.h index d2567047611..a5a66287766 100644 --- a/TAO/tao/RTCORBA/RT_ORB.h +++ b/TAO/tao/RTCORBA/RT_ORB.h @@ -21,7 +21,6 @@ #include "RTCORBA.h" #include "tao/LocalObject.h" -#include "Thread_Pool.h" #include "ace/Hash_Map_Manager_T.h" #if defined(_MSC_VER) @@ -33,6 +32,7 @@ // Forward reference for TAO_Named_RT_Mutex_Manager class TAO_RT_Mutex; +class TAO_Thread_Pool_Manager; /** * @class TAO_Named_RT_Mutex_Manager @@ -269,8 +269,8 @@ protected: /// mutex_mgr_ manages the names associated with named mutexes. TAO_Named_RT_Mutex_Manager mutex_mgr_; - /// Thread Pool Manager. - TAO_Thread_Pool_Manager tp_manager_; + /// Thread Pool Manager + TAO_Thread_Pool_Manager *tp_manager_; }; #if defined (__ACE_INLINE__) diff --git a/TAO/tao/RTCORBA/RT_ORBInitializer.cpp b/TAO/tao/RTCORBA/RT_ORBInitializer.cpp index 674e27f0d04..0921e9e8e23 100644 --- a/TAO/tao/RTCORBA/RT_ORBInitializer.cpp +++ b/TAO/tao/RTCORBA/RT_ORBInitializer.cpp @@ -15,6 +15,7 @@ ACE_RCSID (TAO, RT_ORBInitializer, "$Id$") #include "RT_ORB_Loader.h" #include "RT_Stub_Factory.h" #include "RT_Endpoint_Selector_Factory.h" +#include "RT_Thread_Lane_Resources_Manager.h" #include "ace/Service_Repository.h" #include "ace/Svc_Conf.h" @@ -35,11 +36,26 @@ TAO_RT_ORBInitializer::pre_init ( { TAO_ENV_ARG_DEFN; + // // Register all of the RT related services. + // + + // Set the name of the Protocol_Hooks to be the RT_Protocols_Hooks. + TAO_ORB_Core::set_protocols_hooks ("RT_Protocols_Hooks"); ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Protocols_Hooks); + + // Set the name of the stub factory to be the RT_Stub_Factory. + TAO_ORB_Core::set_stub_factory ("RT_Stub_Factory"); ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Stub_Factory); + + // Set the name of the stub factory to be the RT_Stub_Factory. + TAO_ORB_Core::set_endpoint_selector_factory ("RT_Endpoint_Selector_Factory"); ACE_Service_Config::process_directive (ace_svc_desc_RT_Endpoint_Selector_Factory); + // Set the name of the thread lane resources manager to be the RT_Thread_Lane_Resources_Manager. + TAO_ORB_Core::set_thread_lane_resources_manager ("RT_Thread_Lane_Resources_Manager"); + ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_Thread_Lane_Resources_Manager); + // If the application resolves the root POA, make sure we load the RT POA. TAO_ORB_Core::set_poa_factory (rt_poa_factory_name, rt_poa_factory_directive); @@ -47,15 +63,6 @@ TAO_RT_ORBInitializer::pre_init ( // @@ RTCORBA Subsetting: service gets automatically loaded now by using a static initializer. // ACE_Service_Config::process_directive (ace_svc_desc_TAO_RT_ORB_Loader); - // Set the name of the Protocol_Hooks to be the RT_Protocols_Hooks. - TAO_ORB_Core::set_protocols_hooks ("RT_Protocols_Hooks"); - - // Set the name of the stub factory to be the RT_Stub_Factory. - TAO_ORB_Core::set_stub_factory ("RT_Stub_Factory"); - - // Set the name of the stub factory to be the RT_Stub_Factory. - TAO_ORB_Core::set_endpoint_selector_factory ("RT_Endpoint_Selector_Factory"); - // Set the Priority_Mapping_Manager TAO_Priority_Mapping_Manager *manager = 0; @@ -131,4 +138,3 @@ TAO_RT_ORBInitializer::register_policy_factories ( ACE_TRY_ENV); ACE_CHECK; } - diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp index b1d09e544a7..eae480fccf0 100644 --- a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp @@ -8,7 +8,6 @@ ACE_RCSID(RTCORBA, RT_Thread_Lane_Resources_Manager, "$Id$") #include "tao/Acceptor_Registry.h" #include "tao/Thread_Lane_Resources.h" #include "tao/RTCORBA/Thread_Pool.h" -#include "tao/RTCORBA/RT_ORB.h" #include "tao/Leader_Follower.h" #if !defined (__ACE_INLINE__) @@ -25,6 +24,7 @@ TAO_RT_Thread_Lane_Resources_Manager::TAO_RT_Thread_Lane_Resources_Manager (void TAO_RT_Thread_Lane_Resources_Manager::~TAO_RT_Thread_Lane_Resources_Manager (void) { delete this->default_lane_resources_; + delete this->tp_manager_; } int @@ -40,6 +40,10 @@ TAO_RT_Thread_Lane_Resources_Manager::initialize (TAO_ORB_Core &orb_core) TAO_Thread_Lane_Resources (orb_core), -1); + ACE_NEW_RETURN (this->tp_manager_, + TAO_Thread_Pool_Manager (orb_core), + -1); + return 0; } @@ -128,24 +132,46 @@ TAO_RT_Thread_Lane_Resources_Manager::default_lane_resources (void) } int -TAO_RT_Thread_Lane_Resources_Manager::shutdown_all_reactors (CORBA_Environment &ACE_TRY_ENV) +TAO_RT_Thread_Lane_Resources_Manager::shutdown_default_reactors (CORBA_Environment &ACE_TRY_ENV) { - // Get the RTORB. - CORBA::Object_var object = - this->orb_core_->resolve_rt_orb (ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); + TAO_Leader_Follower &leader_follower = + this->default_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 (); + } - RTCORBA::RTORB_var rt_orb = - RTCORBA::RTORB::_narrow (object, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); + return 0; +} - TAO_RT_ORB *tao_rt_orb = - ACE_dynamic_cast (TAO_RT_ORB *, - rt_orb.in ()); +int +TAO_RT_Thread_Lane_Resources_Manager::shutdown_all_reactors (CORBA_Environment &ACE_TRY_ENV) +{ + int result = + this->shutdown_default_reactors (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); - this->tp_manager_ = - &tao_rt_orb->tp_manager (); + if (result != 0) + return result; TAO_Thread_Pool_Manager::THREAD_POOLS &thread_pools = this->tp_manager_->thread_pools (); @@ -199,6 +225,12 @@ TAO_RT_Thread_Lane_Resources_Manager::shutdown_all_reactors (CORBA_Environment & return 0; } +TAO_Thread_Pool_Manager & +TAO_RT_Thread_Lane_Resources_Manager::tp_manager (void) +{ + return *this->tp_manager_; +} + ACE_STATIC_SVC_DEFINE (TAO_RT_Thread_Lane_Resources_Manager, ACE_TEXT ("RT_Thread_Lane_Resources_Manager"), ACE_SVC_OBJ_T, diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h index 86adcab04cb..139ea32ad63 100644 --- a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h @@ -48,8 +48,13 @@ public: TAO_Thread_Lane_Resources &default_lane_resources (void); int shutdown_all_reactors (CORBA_Environment &ACE_TRY_ENV); + /// Get the Thread Pool Manager. + TAO_Thread_Pool_Manager &tp_manager (void); + protected: + int shutdown_default_reactors (CORBA_Environment &ACE_TRY_ENV); + /// Mutual exclusion for calling open. TAO_SYNCH_MUTEX open_lock_; @@ -58,6 +63,7 @@ protected: TAO_Thread_Lane_Resources *default_lane_resources_; + /// Thread Pool Manager. TAO_Thread_Pool_Manager *tp_manager_; }; -- cgit v1.2.1