diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-07-27 03:07:03 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-07-27 03:07:03 +0000 |
commit | 8c2634bd037d691ecf943668d18b696dd4e356d7 (patch) | |
tree | 5aac9124269a41abda7b7a45ebd564b52816c662 | |
parent | 24f20357f46d0564c79018236ef0d4b32df3838d (diff) | |
download | ATCD-8c2634bd037d691ecf943668d18b696dd4e356d7.tar.gz |
Thread Pool changes....
22 files changed, 607 insertions, 164 deletions
diff --git a/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp b/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp index 20b7d690cca..e3ca26c983c 100644 --- a/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp +++ b/TAO/tao/Default_Thread_Lane_Resources_Manager.cpp @@ -81,6 +81,12 @@ TAO_Default_Thread_Lane_Resources_Manager::lane_resources (void) return *this->lane_resources_; } +TAO_Thread_Lane_Resources & +TAO_Default_Thread_Lane_Resources_Manager::default_lane_resources (void) +{ + return *this->lane_resources_; +} + ACE_STATIC_SVC_DEFINE (TAO_Default_Thread_Lane_Resources_Manager, ACE_TEXT ("Default_Thread_Lane_Resources_Manager"), ACE_SVC_OBJ_T, diff --git a/TAO/tao/Default_Thread_Lane_Resources_Manager.h b/TAO/tao/Default_Thread_Lane_Resources_Manager.h index 97cc3a7a92f..ffbea852256 100644 --- a/TAO/tao/Default_Thread_Lane_Resources_Manager.h +++ b/TAO/tao/Default_Thread_Lane_Resources_Manager.h @@ -43,6 +43,8 @@ public: TAO_Thread_Lane_Resources &lane_resources (void); + TAO_Thread_Lane_Resources &default_lane_resources (void); + /// Mutual exclusion for calling open. TAO_SYNCH_MUTEX open_lock_; diff --git a/TAO/tao/PortableServer/Object_Adapter.cpp b/TAO/tao/PortableServer/Object_Adapter.cpp index a5bb502bd89..c76db656fc7 100644 --- a/TAO/tao/PortableServer/Object_Adapter.cpp +++ b/TAO/tao/PortableServer/Object_Adapter.cpp @@ -21,6 +21,7 @@ #include "tao/debug.h" #include "tao/PortableInterceptor.h" #include "tao/POA_Extension_Initializer.h" +#include "tao/Thread_Lane_Resources_Manager.h" #if !defined (__ACE_INLINE__) # include "Object_Adapter.i" @@ -587,12 +588,18 @@ TAO_Object_Adapter::open (CORBA::Environment &ACE_TRY_ENV) // takes a const reference and makes its own copy of the // policy. (Otherwise, we'd have to allocate the policy // on the heap.) - TAO_Implicit_Activation_Policy implicit_activation_policy ( - PortableServer::IMPLICIT_ACTIVATION); + TAO_Implicit_Activation_Policy + implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION); + policies.merge_policy (&implicit_activation_policy, ACE_TRY_ENV); #endif /* TAO_HAS_MINIMUM_POA == 0 */ + // This makes sure that the default resources are open when the Root + // POA is created. + this->orb_core_.thread_lane_resources_manager ().open_default_resources (ACE_TRY_ENV); + ACE_CHECK; + // Construct a new POA TAO_POA::String root_poa_name (TAO_DEFAULT_ROOTPOA_NAME); this->root_ = this->servant_dispatcher_->create_POA (root_poa_name, diff --git a/TAO/tao/PortableServer/POA.cpp b/TAO/tao/PortableServer/POA.cpp index 267bfedd234..685bdd4c179 100644 --- a/TAO/tao/PortableServer/POA.cpp +++ b/TAO/tao/PortableServer/POA.cpp @@ -16,7 +16,6 @@ #include "tao/Server_Strategy_Factory.h" #include "tao/Acceptor_Registry.h" #include "tao/Thread_Lane_Resources.h" -#include "tao/Thread_Lane_Resources_Manager.h" #include "tao/Environment.h" #include "tao/Exception.h" #include "tao/Stub.h" @@ -386,21 +385,6 @@ TAO_POA::create_POA_i (const char *adapter_name, ACE_TRY_ENV); ACE_CHECK_RETURN (PortableServer::POA::_nil ()); - // Check to see if the user has specfied a thread pool policy. - CORBA::Policy_var policy = - tao_policies.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL); - - // If a thread pool policy was specified, then this POA will be run - // by an RT thread pool. Resources for RT threads pools are opened - // during the creation of the thread pool. - // - // However, if the thread pool was not specified, this POA will be - // run by the default thread pool. Therefore, we have to make sure - // that the resources for the default thread pool are open. - if (CORBA::is_nil (policy.in ())) - this->orb_core_.thread_lane_resources_manager ().open_default_resources (ACE_TRY_ENV); - ACE_CHECK_RETURN (PortableServer::POA::_nil ()); - // If any of the policy objects specified are not valid for the ORB // implementation, if conflicting policy objects are specified, or // if any of the specified policy objects require prior @@ -3258,6 +3242,7 @@ TAO_POA::key_to_stub_i (const TAO_ObjectKey &key, type_id, client_exposed_policies._retn (), &filter, + this->orb_core_.lane_resources ().acceptor_registry (), ACE_TRY_ENV); ACE_CHECK_RETURN (0); @@ -3269,13 +3254,12 @@ TAO_POA::create_stub_object (const TAO_ObjectKey &object_key, const char *type_id, CORBA::PolicyList *policy_list, TAO_Acceptor_Filter *filter, + TAO_Acceptor_Registry &acceptor_registry, CORBA::Environment &ACE_TRY_ENV) { int error = 0; - TAO_Acceptor_Registry &acceptor_registry = - this->orb_core_.lane_resources ().acceptor_registry (); - // Count the number of endpoints. + // Count the number of endpoints. size_t profile_count = acceptor_registry.endpoint_count (); diff --git a/TAO/tao/PortableServer/POA.h b/TAO/tao/PortableServer/POA.h index a2143dcb923..8b57b244be4 100644 --- a/TAO/tao/PortableServer/POA.h +++ b/TAO/tao/PortableServer/POA.h @@ -68,6 +68,7 @@ #endif /* _MSC_VER */ class TAO_Acceptor_Filter; +class TAO_Acceptor_Registry; class TAO_Temporary_Creation_Time; class TAO_Creation_Time @@ -491,6 +492,7 @@ protected: const char *type_id, CORBA::PolicyList *policy_list, TAO_Acceptor_Filter *filter, + TAO_Acceptor_Registry &acceptor_registry, CORBA::Environment &ACE_TRY_ENV); int is_servant_in_map (PortableServer::Servant servant); diff --git a/TAO/tao/PortableServer/POA_Policy_Set.h b/TAO/tao/PortableServer/POA_Policy_Set.h index 82f477a93db..6cc40c0a6bf 100644 --- a/TAO/tao/PortableServer/POA_Policy_Set.h +++ b/TAO/tao/PortableServer/POA_Policy_Set.h @@ -71,6 +71,8 @@ public: void add_client_exposed_fixed_policies (CORBA::PolicyList *client_exposed_policies, CORBA::Environment &ACE_TRY_ENV); + TAO_Policy_Set &policies (void); + protected: TAO_Policy_Set impl_; }; diff --git a/TAO/tao/PortableServer/POA_Policy_Set.i b/TAO/tao/PortableServer/POA_Policy_Set.i index e033967f5d4..94d39143949 100644 --- a/TAO/tao/PortableServer/POA_Policy_Set.i +++ b/TAO/tao/PortableServer/POA_Policy_Set.i @@ -37,3 +37,8 @@ TAO_POA_Policy_Set::merge_policy (const CORBA::Policy_ptr policy, ACE_CHECK; } +ACE_INLINE TAO_Policy_Set & +TAO_POA_Policy_Set::policies (void) +{ + return this->impl_; +} diff --git a/TAO/tao/RTCORBA/RT_ORB.cpp b/TAO/tao/RTCORBA/RT_ORB.cpp index c4505b74963..ae402796759 100644 --- a/TAO/tao/RTCORBA/RT_ORB.cpp +++ b/TAO/tao/RTCORBA/RT_ORB.cpp @@ -68,15 +68,15 @@ TAO_RT_CORBA_Priority_Normalizer::normalize (CORBA::Short corba_priority, return 1; } -TAO_RT_ORB::TAO_RT_ORB (CORBA::ORB_ptr orb) - : orb_ (CORBA::ORB::_duplicate (orb)), +TAO_RT_ORB::TAO_RT_ORB (TAO_ORB_Core *orb_core) + : orb_core_ (orb_core), mutex_mgr_ (), - tp_manager_ (orb) + tp_manager_ (*orb_core) { TAO_RT_CORBA_Priority_Normalizer *corba_priority_normalizer = 0; ACE_NEW (corba_priority_normalizer, - TAO_RT_CORBA_Priority_Normalizer (orb->orb_core ())); - orb->orb_core ()->corba_priority_normalizer (corba_priority_normalizer); + TAO_RT_CORBA_Priority_Normalizer (orb_core)); + orb_core->corba_priority_normalizer (corba_priority_normalizer); } TAO_RT_ORB::~TAO_RT_ORB (void) @@ -320,6 +320,7 @@ TAO_RT_ORB::create_threadpool (CORBA::ULong stacksize, allow_request_buffering, max_buffered_requests, max_request_buffer_size, + 1, ACE_TRY_ENV); } @@ -339,6 +340,7 @@ TAO_RT_ORB::create_threadpool_with_lanes (CORBA::ULong stacksize, allow_request_buffering, max_buffered_requests, max_request_buffer_size, + 1, ACE_TRY_ENV); } @@ -443,6 +445,12 @@ TAO_RT_ORB::create_client_protocol_policy (const RTCORBA::ProtocolList & protoco return tmp; } +TAO_Thread_Pool_Manager & +TAO_RT_ORB::tp_manager (void) +{ + return this->tp_manager_; +} + //////////////////////////////////////////////////////////////////////////////// #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) diff --git a/TAO/tao/RTCORBA/RT_ORB.h b/TAO/tao/RTCORBA/RT_ORB.h index 2d5e45d50ac..d2567047611 100644 --- a/TAO/tao/RTCORBA/RT_ORB.h +++ b/TAO/tao/RTCORBA/RT_ORB.h @@ -105,7 +105,7 @@ class TAO_RTCORBA_Export TAO_RT_ORB { public: /// Constructor. - TAO_RT_ORB (CORBA::ORB_ptr orb); + TAO_RT_ORB (TAO_ORB_Core *orb_core); /** * Create a new mutex. Mutexes returned by this method @@ -255,13 +255,16 @@ public: TAO_default_environment ()) ACE_THROW_SPEC ((CORBA::SystemException)); + /// Get the Thread Pool Manager. + TAO_Thread_Pool_Manager &tp_manager (void); + protected: /// Protected destructor to enforce proper memory management of this /// reference counted object. virtual ~TAO_RT_ORB (void); /// Reference to our creating ORB. - CORBA::ORB_var orb_; + TAO_ORB_Core *orb_core_; /// mutex_mgr_ manages the names associated with named mutexes. TAO_Named_RT_Mutex_Manager mutex_mgr_; diff --git a/TAO/tao/RTCORBA/RT_ORB_Loader.cpp b/TAO/tao/RTCORBA/RT_ORB_Loader.cpp index 82ec69e76e4..9e70b58dd2f 100644 --- a/TAO/tao/RTCORBA/RT_ORB_Loader.cpp +++ b/TAO/tao/RTCORBA/RT_ORB_Loader.cpp @@ -165,12 +165,12 @@ TAO_RT_ORB_Loader::create_object (CORBA::ORB_ptr orb, // Return RT_ORB CORBA::Object_ptr rt_orb = CORBA::Object::_nil (); - // Check that all of the RTCORBA hooks have been initialized + // Check that all of the RTCORBA hooks have been initialized // successfully. if (this->initialized_) { ACE_NEW_THROW_EX (rt_orb, - TAO_RT_ORB (orb), + TAO_RT_ORB (orb->orb_core ()), CORBA::NO_MEMORY ( CORBA::SystemException::_tao_minor_code ( TAO_DEFAULT_MINOR_CODE, diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp index 08c36e5254c..b65ab51514d 100644 --- a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.cpp @@ -1,17 +1,17 @@ // $Id$ -#include "tao/Default_Thread_Lane_Resources_Manager.h" +#include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h" -ACE_RCSID(tao, Default_Thread_Lane_Resources_Manager, "$Id$") +ACE_RCSID(RTCORBA, RT_Thread_Lane_Resources_Manager, "$Id$") #include "tao/ORB_Core.h" #include "tao/Acceptor_Registry.h" #include "tao/Thread_Lane_Resources.h" -#include "tao/Thread_Pool.h" +#include "tao/RTCORBA/Thread_Pool.h" #include "tao/Leader_Follower.h" #if !defined (__ACE_INLINE__) -# include "tao/Default_Thread_Lane_Resources_Manager.i" +# include "tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i" #endif /* ! __ACE_INLINE__ */ TAO_RT_Thread_Lane_Resources_Manager::TAO_RT_Thread_Lane_Resources_Manager (void) @@ -93,6 +93,12 @@ TAO_RT_Thread_Lane_Resources_Manager::lane_resources (void) return *this->default_lane_resources_; } +TAO_Thread_Lane_Resources & +TAO_RT_Thread_Lane_Resources_Manager::default_lane_resources (void) +{ + return *this->default_lane_resources_; +} + 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 0d42b9cb0cd..f1014ef458e 100644 --- a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.h @@ -18,6 +18,7 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/RTCORBA/rtcorba_export.h" #include "tao/Thread_Lane_Resources_Manager.h" #include "ace/Service_Config.h" @@ -43,6 +44,8 @@ public: TAO_Thread_Lane_Resources &lane_resources (void); + TAO_Thread_Lane_Resources &default_lane_resources (void); + /// Mutual exclusion for calling open. TAO_SYNCH_MUTEX open_lock_; @@ -55,8 +58,8 @@ public: TAO_ORB_Core *orb_core_; }; -ACE_STATIC_SVC_DECLARE_EXPORT (TAO, TAO_RT_Thread_Lane_Resources_Manager) -ACE_FACTORY_DECLARE (TAO, TAO_RT_Thread_Lane_Resources_Manager) +ACE_STATIC_SVC_DECLARE_EXPORT (TAO_RTCORBA, TAO_RT_Thread_Lane_Resources_Manager) +ACE_FACTORY_DECLARE (TAO_RTCORBA, TAO_RT_Thread_Lane_Resources_Manager) #if defined (__ACE_INLINE__) # include "tao/RT_Thread_Lane_Resources_Manager.i" diff --git a/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/tao/RTCORBA/RT_Thread_Lane_Resources_Manager.i @@ -0,0 +1 @@ +// $Id$ diff --git a/TAO/tao/RTCORBA/TAO_RTCORBA.dsp b/TAO/tao/RTCORBA/TAO_RTCORBA.dsp index 212051b0044..6d4d499d2f1 100644 --- a/TAO/tao/RTCORBA/TAO_RTCORBA.dsp +++ b/TAO/tao/RTCORBA/TAO_RTCORBA.dsp @@ -242,6 +242,10 @@ SOURCE=.\RTCORBAC.cpp SOURCE=.\Thread_Pool.cpp
# End Source File
+# Begin Source File
+
+SOURCE=.\RT_Thread_Lane_Resources_Manager.cpp
+# End Source File
# End Group
# Begin Group "Header Files"
@@ -338,6 +342,10 @@ SOURCE=.\RTCORBAC.h SOURCE=.\Thread_Pool.h
# End Source File
+# Begin Source File
+
+SOURCE=.\RT_Thread_Lane_Resources_Manager.h
+# End Source File
# End Group
# Begin Group "Inline Files"
@@ -398,6 +406,10 @@ SOURCE=.\RTCORBAC.i SOURCE=.\Thread_Pool.i
# End Source File
+# Begin Source File
+
+SOURCE=.\RT_Thread_Lane_Resources_Manager.i
+# End Source File
# End Group
# Begin Group "Template Files"
diff --git a/TAO/tao/RTCORBA/Thread_Pool.cpp b/TAO/tao/RTCORBA/Thread_Pool.cpp index 869b724ba57..54a4b8dafc2 100644 --- a/TAO/tao/RTCORBA/Thread_Pool.cpp +++ b/TAO/tao/RTCORBA/Thread_Pool.cpp @@ -7,14 +7,16 @@ ACE_RCSID(tao, Thread_Pool, "$Id$") #include "tao/Exception.h" #include "ace/Auto_Ptr.h" #include "tao/ORB_Core.h" +#include "tao/Acceptor_Registry.h" +#include "tao/Transport_Cache_Manager.h" +#include "tao/debug.h" #if !defined (__ACE_INLINE__) # include "Thread_Pool.i" #endif /* ! __ACE_INLINE__ */ -TAO_Thread_Pool_Threads::TAO_Thread_Pool_Threads (TAO_Thread_Lane &lane, - ACE_Thread_Manager &tm) - : ACE_Task_Base (&tm), +TAO_Thread_Pool_Threads::TAO_Thread_Pool_Threads (TAO_Thread_Lane &lane) + : ACE_Task_Base (lane.pool ().manager ().orb_core ().thr_mgr ()), lane_ (lane) { } @@ -28,11 +30,16 @@ TAO_Thread_Pool_Threads::lane (void) const int TAO_Thread_Pool_Threads::svc (void) { - CORBA::ORB_var orb = - this->lane ().thread_pool ().orb (); + TAO_ORB_Core &orb_core = + this->lane ().pool ().manager ().orb_core (); - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY + TAO_Thread_Pool_Threads::set_tss_resources (orb_core, + this->lane_); + + CORBA::ORB_ptr orb = + orb_core.orb (); + + ACE_TRY_NEW_ENV { orb->run (ACE_TRY_ENV); ACE_TRY_CHECK; @@ -47,21 +54,60 @@ TAO_Thread_Pool_Threads::svc (void) return 0; } -TAO_Thread_Lane::TAO_Thread_Lane (TAO_Thread_Pool &thread_pool, +void +TAO_Thread_Pool_Threads::set_tss_resources (TAO_ORB_Core &orb_core, + TAO_Thread_Lane &thread_lane) +{ + /// Get the ORB_Core's TSS resources. + TAO_ORB_Core_TSS_Resources &tss = + *orb_core.get_tss_resources (); + + /// Set the lane attribute in TSS. + tss.lane_ = &thread_lane; +} + +TAO_Thread_Lane::TAO_Thread_Lane (TAO_Thread_Pool &pool, CORBA::ULong id, CORBA::Short lane_priority, CORBA::ULong static_threads, - CORBA::ULong dynamic_threads) - : thread_pool_ (thread_pool), + CORBA::ULong dynamic_threads, + CORBA::Environment &ACE_TRY_ENV) + : pool_ (pool), id_ (id), lane_priority_ (lane_priority), static_threads_ (static_threads), dynamic_threads_ (dynamic_threads), - threads_ (*this, - thread_pool_.thread_manager_) + threads_ (*this), + resources_ (pool.manager ().orb_core ()) +{ +} + +void +TAO_Thread_Lane::open (CORBA::Environment &ACE_TRY_ENV) +{ + int result = 0; + result = + this->resources_.open_acceptor_registry (ACE_TRY_ENV); + ACE_CHECK; + + if (result == -1) + ACE_THROW (CORBA::INTERNAL ( + CORBA_SystemException::_tao_minor_code ( + TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE, + 0), + CORBA::COMPLETED_NO)); +} + +TAO_Thread_Lane::~TAO_Thread_Lane (void) { } +void +TAO_Thread_Lane::fini (void) +{ + this->resources_.finalize (); +} + int TAO_Thread_Lane::create_static_threads (void) { @@ -91,7 +137,8 @@ TAO_Thread_Lane::create_dynamic_threads (CORBA::ULong number_of_threads) for (index = 0; index != number_of_threads; ++index) - stack_size_array[index] = this->thread_pool_.stack_size_; + stack_size_array[index] = + this->pool ().stack_size_; // Make sure the dynamically created stack size array is properly // deleted. @@ -116,9 +163,9 @@ TAO_Thread_Lane::id (void) const } TAO_Thread_Pool & -TAO_Thread_Lane::thread_pool (void) const +TAO_Thread_Lane::pool (void) const { - return this->thread_pool_; + return this->pool_; } CORBA::Short @@ -145,7 +192,14 @@ TAO_Thread_Lane::threads (void) return this->threads_; } -TAO_Thread_Pool::TAO_Thread_Pool (CORBA::ULong id, +TAO_Thread_Lane_Resources & +TAO_Thread_Lane::resources (void) +{ + return this->resources_; +} + +TAO_Thread_Pool::TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager, + CORBA::ULong id, CORBA::ULong stack_size, CORBA::ULong static_threads, CORBA::ULong dynamic_threads, @@ -153,44 +207,44 @@ TAO_Thread_Pool::TAO_Thread_Pool (CORBA::ULong id, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, - CORBA::ORB_ptr orb) - : id_ (id), + CORBA::Environment &ACE_TRY_ENV) + : manager_ (manager), + id_ (id), stack_size_ (stack_size), allow_borrowing_ (0), allow_request_buffering_ (allow_request_buffering), max_buffered_requests_ (max_buffered_requests), max_request_buffer_size_ (max_request_buffer_size), lanes_ (0), - number_of_lanes_ (1), - thread_manager_ (*orb->orb_core ()->thr_mgr ()), - orb_ (CORBA::ORB::_duplicate (orb)) + number_of_lanes_ (1) { this->lanes_ = new TAO_Thread_Lane *[this->number_of_lanes_]; this->lanes_[0] = new TAO_Thread_Lane (*this, 0, default_priority, static_threads, - dynamic_threads); + dynamic_threads, + ACE_TRY_ENV); } -TAO_Thread_Pool::TAO_Thread_Pool (CORBA::ULong id, +TAO_Thread_Pool::TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager, + CORBA::ULong id, CORBA::ULong stack_size, const RTCORBA::ThreadpoolLanes &lanes, CORBA::Boolean allow_borrowing, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, - CORBA::ORB_ptr orb) - : id_ (id), + CORBA::Environment &ACE_TRY_ENV) + : manager_ (manager), + id_ (id), stack_size_ (stack_size), allow_borrowing_ (allow_borrowing), allow_request_buffering_ (allow_request_buffering), max_buffered_requests_ (max_buffered_requests), max_request_buffer_size_ (max_request_buffer_size), lanes_ (0), - number_of_lanes_ (lanes.length ()), - thread_manager_ (*orb->orb_core ()->thr_mgr ()), - orb_ (CORBA::ORB::_duplicate (orb)) + number_of_lanes_ (lanes.length ()) { this->lanes_ = new TAO_Thread_Lane *[this->number_of_lanes_]; for (CORBA::ULong i = 0; @@ -200,7 +254,20 @@ TAO_Thread_Pool::TAO_Thread_Pool (CORBA::ULong id, i, lanes[i].lane_priority, lanes[i].static_threads, - lanes[i].dynamic_threads); + lanes[i].dynamic_threads, + ACE_TRY_ENV); +} + +void +TAO_Thread_Pool::open (CORBA::Environment &ACE_TRY_ENV) +{ + for (CORBA::ULong i = 0; + i != this->number_of_lanes_; + ++i) + { + this->lanes_[i]->open (ACE_TRY_ENV); + ACE_CHECK; + } } TAO_Thread_Pool::~TAO_Thread_Pool (void) @@ -213,6 +280,15 @@ TAO_Thread_Pool::~TAO_Thread_Pool (void) delete[] this->lanes_; } +void +TAO_Thread_Pool::fini (void) +{ + for (CORBA::ULong i = 0; + i != this->number_of_lanes_; + ++i) + this->lanes_[i]->fini (); +} + int TAO_Thread_Pool::create_static_threads (void) { @@ -232,6 +308,12 @@ TAO_Thread_Pool::create_static_threads (void) return 0; } +TAO_Thread_Pool_Manager & +TAO_Thread_Pool::manager (void) const +{ + return this->manager_; +} + CORBA::ULong TAO_Thread_Pool::id (void) const { @@ -280,18 +362,6 @@ TAO_Thread_Pool::number_of_lanes (void) const return this->number_of_lanes_; } -ACE_Thread_Manager & -TAO_Thread_Pool::thread_manager (void) -{ - return this->thread_manager_; -} - -CORBA::ORB_ptr -TAO_Thread_Pool::orb (void) const -{ - return CORBA::ORB::_duplicate (this->orb_.in ()); -} - #define TAO_THREAD_POOL_MANAGER_GUARD \ ACE_GUARD_THROW_EX ( \ ACE_SYNCH_MUTEX, \ @@ -303,10 +373,10 @@ TAO_Thread_Pool::orb (void) const 0), \ CORBA::COMPLETED_NO)); -TAO_Thread_Pool_Manager::TAO_Thread_Pool_Manager (CORBA::ORB_ptr orb) - : orb_ (CORBA::ORB::_duplicate (orb)), +TAO_Thread_Pool_Manager::TAO_Thread_Pool_Manager (TAO_ORB_Core &orb_core) + : orb_core_ (orb_core), thread_pools_ (), - thread_pool_id_counter_ (0), + thread_pool_id_counter_ (1), lock_ () { } @@ -319,6 +389,15 @@ TAO_Thread_Pool_Manager::~TAO_Thread_Pool_Manager (void) delete (*iterator).int_id_; } +void +TAO_Thread_Pool_Manager::fini (void) +{ + for (THREAD_POOLS::ITERATOR iterator = this->thread_pools_.begin (); + iterator != this->thread_pools_.end (); + ++iterator) + (*iterator).int_id_->fini (); +} + RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool (CORBA::ULong stacksize, CORBA::ULong static_threads, @@ -327,6 +406,7 @@ TAO_Thread_Pool_Manager::create_threadpool (CORBA::ULong stacksize, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { @@ -340,6 +420,7 @@ TAO_Thread_Pool_Manager::create_threadpool (CORBA::ULong stacksize, allow_request_buffering, max_buffered_requests, max_request_buffer_size, + call_open, ACE_TRY_ENV); } @@ -350,6 +431,7 @@ TAO_Thread_Pool_Manager::create_threadpool_with_lanes (CORBA::ULong stacksize, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { @@ -362,6 +444,7 @@ TAO_Thread_Pool_Manager::create_threadpool_with_lanes (CORBA::ULong stacksize, allow_request_buffering, max_buffered_requests, max_request_buffer_size, + call_open, ACE_TRY_ENV); } @@ -386,6 +469,7 @@ TAO_Thread_Pool_Manager::create_threadpool_i (CORBA::ULong stacksize, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { @@ -393,7 +477,8 @@ TAO_Thread_Pool_Manager::create_threadpool_i (CORBA::ULong stacksize, TAO_Thread_Pool *thread_pool = 0; ACE_NEW_THROW_EX (thread_pool, - TAO_Thread_Pool (this->thread_pool_id_counter_, + TAO_Thread_Pool (*this, + this->thread_pool_id_counter_, stacksize, static_threads, dynamic_threads, @@ -401,11 +486,12 @@ TAO_Thread_Pool_Manager::create_threadpool_i (CORBA::ULong stacksize, allow_request_buffering, max_buffered_requests, max_request_buffer_size, - this->orb_.in ()), + ACE_TRY_ENV), CORBA::NO_MEMORY ()); ACE_CHECK_RETURN (0); return this->create_threadpool_helper (thread_pool, + call_open, ACE_TRY_ENV); } @@ -416,6 +502,7 @@ TAO_Thread_Pool_Manager::create_threadpool_with_lanes_i (CORBA::ULong stacksize, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { @@ -423,29 +510,39 @@ TAO_Thread_Pool_Manager::create_threadpool_with_lanes_i (CORBA::ULong stacksize, TAO_Thread_Pool *thread_pool = 0; ACE_NEW_THROW_EX (thread_pool, - TAO_Thread_Pool (this->thread_pool_id_counter_, + TAO_Thread_Pool (*this, + this->thread_pool_id_counter_, stacksize, lanes, allow_borrowing, allow_request_buffering, max_buffered_requests, max_request_buffer_size, - this->orb_.in ()), + ACE_TRY_ENV), CORBA::NO_MEMORY ()); ACE_CHECK_RETURN (0); return this->create_threadpool_helper (thread_pool, + call_open, ACE_TRY_ENV); } RTCORBA::ThreadpoolId TAO_Thread_Pool_Manager::create_threadpool_helper (TAO_Thread_Pool *thread_pool, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { // Make sure of safe deletion in case of errors. auto_ptr<TAO_Thread_Pool> safe_thread_pool (thread_pool); + // If required, open the pool. + if (call_open) + { + thread_pool->open (ACE_TRY_ENV); + ACE_CHECK_RETURN (0); + } + // Create the static threads. int result = thread_pool->create_static_threads (); @@ -497,6 +594,12 @@ TAO_Thread_Pool_Manager::destroy_threadpool_i (RTCORBA::ThreadpoolId thread_pool delete thread_pool; } +TAO_ORB_Core & +TAO_Thread_Pool_Manager::orb_core (void) const +{ + return this->orb_core_; +} + TAO_Thread_Pool_Manager::THREAD_POOLS & TAO_Thread_Pool_Manager::thread_pools (void) { @@ -529,4 +632,3 @@ template class ACE_Auto_Basic_Array_Ptr<size_t>; #pragma instantiate ACE_Auto_Basic_Array_Ptr<size_t> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - diff --git a/TAO/tao/RTCORBA/Thread_Pool.h b/TAO/tao/RTCORBA/Thread_Pool.h index 6f337458ea9..45b9e91b1ae 100644 --- a/TAO/tao/RTCORBA/Thread_Pool.h +++ b/TAO/tao/RTCORBA/Thread_Pool.h @@ -20,8 +20,8 @@ #include "ace/Task.h" #include "RTCORBA.h" -#include "tao/ORB.h" #include "ace/Hash_Map_Manager.h" +#include "tao/Thread_Lane_Resources.h" class TAO_Thread_Lane; @@ -38,8 +38,7 @@ class TAO_RTCORBA_Export TAO_Thread_Pool_Threads : public ACE_Task_Base public: /// Constructor. - TAO_Thread_Pool_Threads (TAO_Thread_Lane &lane, - ACE_Thread_Manager &tm); + TAO_Thread_Pool_Threads (TAO_Thread_Lane &lane); /// Method executed when a thread is spawned. int svc (void); @@ -47,6 +46,10 @@ public: /// Accessor to the lane to which this thread belongs to. TAO_Thread_Lane &lane (void) const; + /// Set TSS resources for the current thread. + static void set_tss_resources (TAO_ORB_Core &orb_core, + TAO_Thread_Lane &thread_lane); + private: /// Lane to which this thread belongs to. @@ -72,7 +75,17 @@ public: CORBA::ULong id, CORBA::Short lane_priority, CORBA::ULong static_threads, - CORBA::ULong dynamic_threads); + CORBA::ULong dynamic_threads, + CORBA::Environment &ACE_TRY_ENV); + + /// Destructor. + ~TAO_Thread_Lane (void); + + /// Open the lane. + void open (CORBA::Environment &ACE_TRY_ENV); + + /// Finalize the resources. + void fini (void); /// Create the static threads - only called once. int create_static_threads (void); @@ -84,20 +97,21 @@ public: /// @name Accessors // @{ + TAO_Thread_Pool &pool (void) const; + CORBA::ULong id (void) const; + CORBA::Short lane_priority (void) const; CORBA::ULong static_threads (void) const; CORBA::ULong dynamic_threads (void) const; - CORBA::ULong id (void) const; - - TAO_Thread_Pool &thread_pool (void) const; TAO_Thread_Pool_Threads &threads (void); + TAO_Thread_Lane_Resources &resources (void); // @} private: - TAO_Thread_Pool &thread_pool_; + TAO_Thread_Pool &pool_; CORBA::ULong id_; CORBA::Short lane_priority_; @@ -105,8 +119,12 @@ private: CORBA::ULong dynamic_threads_; TAO_Thread_Pool_Threads threads_; + + TAO_Thread_Lane_Resources resources_; }; +class TAO_Thread_Pool_Manager; + /** * @class TAO_Thread_Pool * @@ -123,7 +141,8 @@ class TAO_RTCORBA_Export TAO_Thread_Pool public: /// Constructor (for pools without lanes). - TAO_Thread_Pool (CORBA::ULong id, + TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager, + CORBA::ULong id, CORBA::ULong stack_size, CORBA::ULong static_threads, CORBA::ULong dynamic_threads, @@ -131,27 +150,35 @@ public: CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, - CORBA::ORB_ptr orb); + CORBA::Environment &ACE_TRY_ENV); /// Constructor (for pools with lanes). - TAO_Thread_Pool (CORBA::ULong id, + TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager, + CORBA::ULong id, CORBA::ULong stack_size, const RTCORBA::ThreadpoolLanes &lanes, CORBA::Boolean allow_borrowing, CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, - CORBA::ORB_ptr orb); + CORBA::Environment &ACE_TRY_ENV); /// Destructor. ~TAO_Thread_Pool (void); + /// Open the pool. + void open (CORBA::Environment &ACE_TRY_ENV); + + /// Finalize the resources. + void fini (void); + /// Create the static threads - only called once. int create_static_threads (void); /// @name Accessors // @{ + TAO_Thread_Pool_Manager &manager (void) const; CORBA::ULong id (void) const; CORBA::ULong stack_size (void) const; @@ -160,9 +187,6 @@ public: CORBA::ULong max_buffered_requests (void) const; CORBA::ULong max_request_buffer_size (void) const; - ACE_Thread_Manager &thread_manager (void); - - CORBA::ORB_ptr orb (void) const; TAO_Thread_Lane **lanes (void); CORBA::ULong number_of_lanes (void) const; @@ -170,6 +194,7 @@ public: private: + TAO_Thread_Pool_Manager &manager_; CORBA::ULong id_; CORBA::ULong stack_size_; @@ -180,12 +205,10 @@ private: TAO_Thread_Lane **lanes_; CORBA::ULong number_of_lanes_; - - ACE_Thread_Manager &thread_manager_; - - CORBA::ORB_var orb_; }; +class TAO_ORB_Core; + /** * @class TAO_Thread_Pool_Manager * @@ -199,11 +222,14 @@ class TAO_RTCORBA_Export TAO_Thread_Pool_Manager public: /// Constructor. - TAO_Thread_Pool_Manager (CORBA::ORB_ptr orb); + TAO_Thread_Pool_Manager (TAO_ORB_Core &orb_core); /// Destructor. ~TAO_Thread_Pool_Manager (void); + /// Finalize the resources. + void fini (void); + /// Create the static threads - only called once. int create_static_threads (void); @@ -217,7 +243,8 @@ public: CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, - CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()) + int call_open, + CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)); /// Create a threadpool with lanes. @@ -228,16 +255,20 @@ public: CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, - CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()) + int call_open, + CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)); /// Destroy a threadpool. void destroy_threadpool (RTCORBA::ThreadpoolId threadpool, - CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()) + CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException, RTCORBA::RTORB::InvalidThreadpool)); + /// ORB_Core accessor. + TAO_ORB_Core &orb_core (void) const; + /// Collection of thread pools. typedef ACE_Hash_Map_Manager<RTCORBA::ThreadpoolId, TAO_Thread_Pool *, ACE_Null_Mutex> THREAD_POOLS; @@ -257,6 +288,7 @@ private: CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)); @@ -267,6 +299,7 @@ private: CORBA::Boolean allow_request_buffering, CORBA::ULong max_buffered_requests, CORBA::ULong max_request_buffer_size, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)); @@ -277,12 +310,13 @@ private: RTCORBA::ThreadpoolId create_threadpool_helper (TAO_Thread_Pool *thread_pool, + int call_open, CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)); // @} - CORBA::ORB_var orb_; + TAO_ORB_Core &orb_core_; THREAD_POOLS thread_pools_; RTCORBA::ThreadpoolId thread_pool_id_counter_; diff --git a/TAO/tao/RTPortableServer/RT_POA.cpp b/TAO/tao/RTPortableServer/RT_POA.cpp index eff96c88cfd..52168a40766 100644 --- a/TAO/tao/RTPortableServer/RT_POA.cpp +++ b/TAO/tao/RTPortableServer/RT_POA.cpp @@ -9,11 +9,14 @@ #include "tao/Exception.h" #include "tao/Stub.h" #include "tao/debug.h" +#include "tao/RTCORBA/Thread_Pool.h" +#include "tao/Thread_Lane_Resources.h" #include "tao/Acceptor_Registry.h" #include "tao/RTCORBA/RT_Policy_i.h" #include "tao/PortableServer/Default_Acceptor_Filter.h" +#include "tao/RTPortableServer/RT_Policy_Validator.h" #include "RT_Acceptor_Filters.h" // auto_ptr class @@ -42,7 +45,8 @@ TAO_RT_POA::TAO_RT_POA (const TAO_POA::String &name, thread_lock, orb_core, object_adapter, - ACE_TRY_ENV) + ACE_TRY_ENV), + thread_pool_ (0) { ACE_CHECK; @@ -89,28 +93,38 @@ void TAO_RT_POA::parse_rt_policies (TAO_POA_Policy_Set &policies, CORBA::Environment &ACE_TRY_ENV) { - CORBA::Policy_var policy = - policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL); + { + CORBA::Policy_var policy = + policies.get_cached_policy (TAO_CACHED_POLICY_PRIORITY_MODEL); - RTCORBA::PriorityModelPolicy_var priority_model = - RTCORBA::PriorityModelPolicy::_narrow (policy.in (), - ACE_TRY_ENV); - ACE_CHECK; + RTCORBA::PriorityModelPolicy_var priority_model = + RTCORBA::PriorityModelPolicy::_narrow (policy.in (), + ACE_TRY_ENV); + ACE_CHECK; - if (!CORBA::is_nil (priority_model.in ())) - { - RTCORBA::PriorityModel rt_priority_model = - priority_model->priority_model (ACE_TRY_ENV); - ACE_CHECK; + if (!CORBA::is_nil (priority_model.in ())) + { + RTCORBA::PriorityModel rt_priority_model = + priority_model->priority_model (ACE_TRY_ENV); + ACE_CHECK; - this->cached_policies ().priority_model ( - TAO_POA_Cached_Policies::PriorityModel (rt_priority_model)); + this->cached_policies ().priority_model ( + TAO_POA_Cached_Policies::PriorityModel ( + rt_priority_model)); - RTCORBA::Priority priority = priority_model->server_priority (ACE_TRY_ENV); + RTCORBA::Priority priority = + priority_model->server_priority (ACE_TRY_ENV); ACE_CHECK; this->cached_policies ().server_priority (priority); } + } + + this->thread_pool_ = + TAO_POA_RT_Policy_Validator::extract_thread_pool (this->orb_core_, + policies.policies (), + ACE_TRY_ENV); + ACE_CHECK; } void @@ -152,10 +166,13 @@ TAO_RT_POA::valid_priority (RTCORBA::Priority priority, else // Case 2. { - TAO_Acceptor_Registry &ar = - this->orb_core_.lane_resources ().acceptor_registry (); + TAO_Acceptor_Registry *ar = + TAO_POA_RT_Policy_Validator::extract_acceptor_registry (this->orb_core_, + this->thread_pool_); - for (TAO_Acceptor **a = ar.begin (); a != ar.end (); ++a) + for (TAO_Acceptor **a = ar->begin (); + a != ar->end (); + ++a) { if ((*a)->priority () == priority) return; @@ -195,6 +212,115 @@ TAO_RT_POA::validate_policies (CORBA::Environment &ACE_TRY_ENV) // observed. } +size_t +TAO_RT_POA::endpoint_count (void) +{ + size_t profile_count = 0; + + TAO_Thread_Lane **lanes = + this->thread_pool_->lanes (); + + for (CORBA::ULong i = 0; + i != this->thread_pool_->number_of_lanes (); + ++i) + profile_count += + lanes[i]->resources ().acceptor_registry ().endpoint_count (); + + return profile_count; +} + +TAO_Stub * +TAO_RT_POA::create_stub_object (const TAO_ObjectKey &object_key, + const char *type_id, + CORBA::PolicyList *policy_list, + TAO_Acceptor_Filter *filter, + CORBA::Environment &ACE_TRY_ENV) +{ + if (this->thread_pool_ == 0) + { + TAO_Acceptor_Registry *acceptor_registry = + TAO_POA_RT_Policy_Validator::extract_acceptor_registry (this->orb_core_, + this->thread_pool_); + + return + this->TAO_POA::create_stub_object (object_key, + type_id, + policy_list, + filter, + *acceptor_registry, + ACE_TRY_ENV); + } + + int error = 0; + + // Count the number of endpoints. + size_t profile_count = + this->endpoint_count (); + + // Create a profile container and have acceptor registries populate + // it with profiles as appropriate. + TAO_MProfile mprofile (0); + + // Allocate space for storing the profiles. There can never be more + // profiles than there are endpoints. In some cases, there can be + // less profiles than endpoints. + int result = + mprofile.set (profile_count); + if (result == -1) + error = 1; + + TAO_Thread_Lane **lanes = + this->thread_pool_->lanes (); + + // Leave it to the filter to decide which acceptors/in which order + // go into the mprofile. + for (CORBA::ULong i = 0; + i != this->thread_pool_->number_of_lanes () && + !error; + ++i) + { + TAO_Acceptor_Registry &acceptor_registry = + lanes[i]->resources ().acceptor_registry (); + + result = + filter->fill_mprofile (object_key, + mprofile, + acceptor_registry.begin (), + acceptor_registry.end ()); + if (result == -1) + error = 1; + } + + if (!error) + result = filter->encode_endpoints (mprofile); + if (result == -1) + error = 1; + + if (error) + ACE_THROW_RETURN (CORBA::INTERNAL ( + CORBA::SystemException::_tao_minor_code ( + TAO_MPROFILE_CREATION_ERROR, + 0), + CORBA::COMPLETED_NO), + 0); + + // Make sure we have at least one profile. <mp> may end up being + // empty if none of the acceptor endpoints have the right priority + // for this object, for example. + if (mprofile.profile_count () == 0) + ACE_THROW_RETURN (CORBA::BAD_PARAM ( + CORBA::SystemException::_tao_minor_code ( + TAO_MPROFILE_CREATION_ERROR, + 0), + CORBA::COMPLETED_NO), + 0); + + return + this->orb_core_.create_stub_object (mprofile, + type_id, + policy_list, + ACE_TRY_ENV); +} TAO_Stub * TAO_RT_POA::key_to_stub_i (const TAO_ObjectKey &key, @@ -252,11 +378,12 @@ TAO_RT_POA::key_to_stub_i (const TAO_ObjectKey &key, filter (server_protocol->protocols_rep (), priority_bands_i->priority_bands_rep()); - data = this->orb_core_.create_stub_object (key, - type_id, - client_exposed_policies._retn (), - &filter, - ACE_TRY_ENV); + data = + this->create_stub_object (key, + type_id, + client_exposed_policies._retn (), + &filter, + ACE_TRY_ENV); ACE_CHECK_RETURN (0); } else @@ -267,11 +394,12 @@ TAO_RT_POA::key_to_stub_i (const TAO_ObjectKey &key, TAO_Priority_Acceptor_Filter filter (server_protocol->protocols_rep (), object_priority); - data = this->orb_core_.create_stub_object (key, - type_id, - client_exposed_policies._retn (), - &filter, - ACE_TRY_ENV); + data = + this->create_stub_object (key, + type_id, + client_exposed_policies._retn (), + &filter, + ACE_TRY_ENV); ACE_CHECK_RETURN (0); } } @@ -279,11 +407,12 @@ TAO_RT_POA::key_to_stub_i (const TAO_ObjectKey &key, { // Client propagated. TAO_Server_Protocol_Acceptor_Filter filter (server_protocol->protocols_rep ()); - data = this->orb_core_.create_stub_object (key, - type_id, - client_exposed_policies._retn (), - &filter, - ACE_TRY_ENV); + data = + this->create_stub_object (key, + type_id, + client_exposed_policies._retn (), + &filter, + ACE_TRY_ENV); ACE_CHECK_RETURN (0); } diff --git a/TAO/tao/RTPortableServer/RT_POA.h b/TAO/tao/RTPortableServer/RT_POA.h index 89654538476..70b7c4ee12b 100644 --- a/TAO/tao/RTPortableServer/RT_POA.h +++ b/TAO/tao/RTPortableServer/RT_POA.h @@ -39,6 +39,8 @@ #pragma warning(disable:4250) #endif /* _MSC_VER */ +class TAO_Thread_Pool; + class TAO_RTPortableServer_Export TAO_RT_POA : public virtual RTPortableServer::POA, public virtual TAO_POA @@ -290,6 +292,16 @@ protected: void parse_rt_policies (TAO_POA_Policy_Set &policies, CORBA::Environment &ACE_TRY_ENV); + size_t endpoint_count (void); + + TAO_Stub *create_stub_object (const TAO_ObjectKey &object_key, + const char *type_id, + CORBA::PolicyList *policy_list, + TAO_Acceptor_Filter *filter, + CORBA::Environment &ACE_TRY_ENV); + + TAO_Thread_Pool *thread_pool_; + }; #if defined(_MSC_VER) && (_MSC_VER >= 1200) diff --git a/TAO/tao/RTPortableServer/RT_POA_Initializer.cpp b/TAO/tao/RTPortableServer/RT_POA_Initializer.cpp index 4be11dea699..6246591db3e 100644 --- a/TAO/tao/RTPortableServer/RT_POA_Initializer.cpp +++ b/TAO/tao/RTPortableServer/RT_POA_Initializer.cpp @@ -27,7 +27,7 @@ TAO_RT_POA_Initializer::register_hooks_impl (TAO_Object_Adapter &object_adapter, // Create and add the RT policy validator. TAO_POA_RT_Policy_Validator *rt_validator; ACE_NEW (rt_validator, - TAO_POA_RT_Policy_Validator (&object_adapter.orb_core ())); + TAO_POA_RT_Policy_Validator (object_adapter.orb_core ())); object_adapter.validator ().add_validator (rt_validator); diff --git a/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp b/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp index 895a53d6fab..f3272685092 100644 --- a/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp +++ b/TAO/tao/RTPortableServer/RT_Policy_Validator.cpp @@ -4,12 +4,18 @@ #include "tao/PortableServer/PortableServerC.h" #include "tao/ORB_Core.h" #include "tao/RTCORBA/RT_Policy_i.h" +#include "tao/RTCORBA/Thread_Pool.h" +#include "tao/RTCORBA/RT_ORB.h" +#include "tao/Thread_Lane_Resources_Manager.h" +#include "tao/Thread_Lane_Resources.h" #include "tao/Acceptor_Registry.h" ACE_RCSID(tao, POA, "$Id$") TAO_POA_RT_Policy_Validator::TAO_POA_RT_Policy_Validator (TAO_ORB_Core &orb_core) - : TAO_POA_Policy_Validator (orb_core) + : TAO_POA_Policy_Validator (orb_core), + acceptor_registry_ (0), + thread_pool_ (0) { // No-Op. } @@ -19,17 +25,27 @@ TAO_POA_RT_Policy_Validator::~TAO_POA_RT_Policy_Validator (void) // No-Op. } +TAO_Acceptor_Registry * +TAO_POA_RT_Policy_Validator::acceptor_registry (void) +{ + if (this->acceptor_registry_ == 0) + this->acceptor_registry_ = + TAO_POA_RT_Policy_Validator::extract_acceptor_registry (this->orb_core_, + this->thread_pool_); + return this->acceptor_registry_; +} + void TAO_POA_RT_Policy_Validator::validate_impl (TAO_Policy_Set &policies, CORBA::Environment &ACE_TRY_ENV) { - this->validate_server_protocol (policies, ACE_TRY_ENV); + this->validate_thread_pool (policies, ACE_TRY_ENV); ACE_CHECK; - this->validate_priorities (policies, ACE_TRY_ENV); + this->validate_server_protocol (policies, ACE_TRY_ENV); ACE_CHECK; - this->validate_thread_pool (policies, ACE_TRY_ENV); + this->validate_priorities (policies, ACE_TRY_ENV); ACE_CHECK; } @@ -65,19 +81,28 @@ TAO_POA_RT_Policy_Validator::validate_server_protocol (TAO_Policy_Set &policies, RTCORBA::ProtocolList &protocols = server_protocol->protocols_rep (); - TAO_Acceptor_Registry *ar = this->orb_core_.acceptor_registry (); + TAO_Acceptor_Registry *acceptor_registry = + this->acceptor_registry (); for (CORBA::ULong j = 0; j < protocols.length (); ++j) { + int found = 0; CORBA::ULong protocol_type = protocols[j].protocol_type; - for (TAO_AcceptorSetIterator a = ar->begin (); a != ar->end (); ++a) + for (TAO_AcceptorSetIterator a = acceptor_registry->begin (); + a != acceptor_registry->end (); + ++a) { if ((*a)->tag () == protocol_type) - return; + { + found = 1; + break; + } } + + if (!found) + ACE_THROW (PortableServer::POA::InvalidPolicy ()); } - ACE_THROW (PortableServer::POA::InvalidPolicy ()); } void @@ -158,7 +183,9 @@ TAO_POA_RT_Policy_Validator::validate_priorities (TAO_Policy_Set &policies, } // Check 3. - TAO_Acceptor_Registry *ar = this->orb_core_.acceptor_registry (); + TAO_Acceptor_Registry *ar = + this->acceptor_registry (); + for (CORBA::ULong i = 0; i < bands.length (); ++i) { int match = 0; @@ -187,7 +214,8 @@ TAO_POA_RT_Policy_Validator::validate_priorities (TAO_Policy_Set &policies, // priority. if (rt_priority_model == RTCORBA::SERVER_DECLARED) { - TAO_Acceptor_Registry *ar = this->orb_core_.acceptor_registry (); + TAO_Acceptor_Registry *ar = + this->acceptor_registry (); for (TAO_AcceptorSetIterator a = ar->begin (); a != ar->end (); ++a) { @@ -203,23 +231,100 @@ void TAO_POA_RT_Policy_Validator::validate_thread_pool (TAO_Policy_Set &policies, CORBA::Environment &ACE_TRY_ENV) { + this->thread_pool_ = + TAO_POA_RT_Policy_Validator::extract_thread_pool (this->orb_core_, + policies, + ACE_TRY_ENV); + ACE_CHECK; +} + +/* static */ +TAO_Thread_Pool * +TAO_POA_RT_Policy_Validator::extract_thread_pool (TAO_ORB_Core &orb_core, + TAO_Policy_Set &policies, + CORBA::Environment &ACE_TRY_ENV) +{ CORBA::Policy_var policy = policies.get_cached_policy (TAO_CACHED_POLICY_THREADPOOL); - RTCORBA::ThreadpoolPolicy_var thread_pool = + RTCORBA::ThreadpoolPolicy_var thread_pool_policy = RTCORBA::ThreadpoolPolicy::_narrow (policy.in (), ACE_TRY_ENV); - ACE_CHECK; + ACE_CHECK_RETURN (0); - if (!CORBA::is_nil (thread_pool.in ())) + if (CORBA::is_nil (thread_pool_policy.in ())) + return 0; + + RTCORBA::ThreadpoolId thread_pool_id = + thread_pool_policy->threadpool (ACE_TRY_ENV); + ACE_CHECK_RETURN (0); + + // Get the RTORB. + CORBA::Object_var object = + orb_core.resolve_rt_orb (ACE_TRY_ENV); + ACE_CHECK_RETURN (0); + + RTCORBA::RTORB_var rt_orb = + RTCORBA::RTORB::_narrow (object, + ACE_TRY_ENV); + ACE_CHECK_RETURN (0); + + TAO_RT_ORB *tao_rt_orb = + ACE_dynamic_cast (TAO_RT_ORB *, + rt_orb.in ()); + + TAO_Thread_Pool_Manager &tp_manager = + tao_rt_orb->tp_manager (); + + TAO_Thread_Pool_Manager::THREAD_POOLS &thread_pools = + tp_manager.thread_pools (); + + // Check that the thread pool id is valid. + TAO_Thread_Pool *thread_pool = 0; + int result = + thread_pools.find (thread_pool_id, + thread_pool); + + if (result != 0) + ACE_THROW_RETURN (PortableServer::POA::InvalidPolicy (), + 0); + + return thread_pool; +} + +/* static */ +TAO_Acceptor_Registry * +TAO_POA_RT_Policy_Validator::extract_acceptor_registry (TAO_ORB_Core &orb_core, + TAO_Thread_Pool *thread_pool) +{ + TAO_Acceptor_Registry *acceptor_registry = 0; + + // If <thread_pool_> != 0, it means that we have a RT thread pool. + if (thread_pool) { - RTCORBA::ThreadpoolId thread_pool_id = - = thread_pool->thread_pool (ACE_TRY_ENV); - ACE_CHECK; + TAO_Thread_Lane **lanes = + thread_pool->lanes (); - // Check that the thread pool id is valid. - int result = - find (thread_pool_id); - if (result != 0) - ACE_THROW (PortableServer::POA::InvalidPolicy ()); + // All the lanes have similar acceptor registries. Therefore, + // looking at the first lane should suffice. + TAO_Thread_Lane_Resources &resources = + lanes[0]->resources (); + + acceptor_registry = + &resources.acceptor_registry (); } + else + // We are dealing with the default thread pool. + { + TAO_Thread_Lane_Resources_Manager &thread_lane_resources_manager = + orb_core.thread_lane_resources_manager (); + + TAO_Thread_Lane_Resources &resources = + thread_lane_resources_manager.default_lane_resources (); + + acceptor_registry = + &resources.acceptor_registry (); + } + + return acceptor_registry; +} diff --git a/TAO/tao/RTPortableServer/RT_Policy_Validator.h b/TAO/tao/RTPortableServer/RT_Policy_Validator.h index b1420068050..493f6db0f43 100644 --- a/TAO/tao/RTPortableServer/RT_Policy_Validator.h +++ b/TAO/tao/RTPortableServer/RT_Policy_Validator.h @@ -25,6 +25,8 @@ #include "tao/PortableServer/Policy_Validator.h" class TAO_ORB_Core; +class TAO_Acceptor_Registry; +class TAO_Thread_Pool; class TAO_RTPortableServer_Export TAO_POA_RT_Policy_Validator : public TAO_POA_Policy_Validator @@ -36,6 +38,13 @@ public: /// Destructor. ~TAO_POA_RT_Policy_Validator (void); + static TAO_Thread_Pool *extract_thread_pool (TAO_ORB_Core &orb_core, + TAO_Policy_Set &policies, + CORBA::Environment &ACE_TRY_ENV); + + static TAO_Acceptor_Registry *extract_acceptor_registry (TAO_ORB_Core &orb_core, + TAO_Thread_Pool *thread_pool); + protected: /** @@ -60,6 +69,16 @@ private: void validate_priorities (TAO_Policy_Set &policies, CORBA::Environment &ACE_TRY_ENV); + + void validate_thread_pool (TAO_Policy_Set &policies, + CORBA::Environment &ACE_TRY_ENV); + + TAO_Acceptor_Registry *acceptor_registry (void); + + TAO_Acceptor_Registry *acceptor_registry_; + + TAO_Thread_Pool *thread_pool_; + }; #include "ace/post.h" diff --git a/TAO/tao/Thread_Lane_Resources_Manager.h b/TAO/tao/Thread_Lane_Resources_Manager.h index 21a2522872f..45522d596b4 100644 --- a/TAO/tao/Thread_Lane_Resources_Manager.h +++ b/TAO/tao/Thread_Lane_Resources_Manager.h @@ -41,6 +41,7 @@ public: virtual int open_default_resources (CORBA_Environment &ACE_TRY_ENV) = 0; virtual TAO_Thread_Lane_Resources &lane_resources (void) = 0; + virtual TAO_Thread_Lane_Resources &default_lane_resources (void) = 0; }; #if defined (__ACE_INLINE__) |