diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2005-01-19 16:53:12 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2005-01-19 16:53:12 +0000 |
commit | bcb037fce9d2fe2fbcb323f54fd0c6e608f1c930 (patch) | |
tree | 4f0421a430c5fe5c68ba80bd904c12b32359d5a4 /TAO/tao | |
parent | b5df36f326615e592adae99098c9e37e38f0e061 (diff) | |
download | ATCD-bcb037fce9d2fe2fbcb323f54fd0c6e608f1c930.tar.gz |
ChangeLogTag:Wed Jan 19 09:31:05 2005 Ossama Othman <ossama@dre.vanderbilt.edu>
Diffstat (limited to 'TAO/tao')
-rw-r--r-- | TAO/tao/ORB.cpp | 129 | ||||
-rw-r--r-- | TAO/tao/ORB.h | 22 | ||||
-rw-r--r-- | TAO/tao/ORBInitializer_Registry.cpp | 81 | ||||
-rw-r--r-- | TAO/tao/ORBInitializer_Registry.h | 120 | ||||
-rw-r--r-- | TAO/tao/ORB_Core.cpp | 69 | ||||
-rw-r--r-- | TAO/tao/ORB_Table.cpp | 109 | ||||
-rw-r--r-- | TAO/tao/ORB_Table.h | 160 | ||||
-rw-r--r-- | TAO/tao/ORB_Table.inl | 2 | ||||
-rw-r--r-- | TAO/tao/TAO_Internal.cpp | 406 | ||||
-rw-r--r-- | TAO/tao/TAO_Internal.h | 95 |
10 files changed, 634 insertions, 559 deletions
diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp index a49d6a35bd1..b2ea6fff80d 100644 --- a/TAO/tao/ORB.cpp +++ b/TAO/tao/ORB.cpp @@ -59,8 +59,11 @@ static const char ior_prefix[] = "IOR:"; // = Static initialization. -// Count of the number of ORBs. -int CORBA::ORB::orb_init_count_ = 0; +namespace +{ + // Count of the number of ORBs. + int orb_init_count = 0; +} // **************************************************************** @@ -1284,19 +1287,19 @@ CORBA::ORB::check_shutdown (ACE_ENV_SINGLE_ARG_DECL) // **************************************************************** void -CORBA::ORB::init_orb_globals (ACE_ENV_SINGLE_ARG_DECL) +TAO::ORB::init_orb_globals (ACE_ENV_SINGLE_ARG_DECL) { // This method should be invoked atomically. It is the caller's // responsibility to ensure that this condition is satisfied. // Prevent multiple initializations. - if (CORBA::ORB::orb_init_count_ != 0) + if (orb_init_count != 0) { return; } else { - ++CORBA::ORB::orb_init_count_; + ++orb_init_count; } // initialize the system TypeCodes @@ -1437,10 +1440,12 @@ CORBA::ORB_init (int &argc, return CORBA::ORB::_nil (); } + CORBA::Environment & env (TAO_default_environment ()); + return CORBA::ORB_init (argc, argv, orb_name, - TAO_default_environment ()); + env); } CORBA::ORB_ptr @@ -1453,25 +1458,28 @@ CORBA::ORB_init (int &argc, ACE_UNUSED_ARG(ACE_TRY_ENV); // FUZZ: ignore check_for_ace_check // Use this string variable to hold the orbid - ACE_CString orbid_string = orbid; + ACE_CString orbid_string (orbid); // Copy command line parameter not to use original. ACE_Argv_Type_Converter command_line(argc, argv); - // Using ACE_Static_Object_Lock::instance() precludes <ORB_init> - // from being called within a static object CTOR. - ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, - *ACE_Static_Object_Lock::instance (), - CORBA::ORB::_nil ())); - - // Make sure TAO's singleton manager is initialized. - if (TAO_Singleton_Manager::instance ()->init () == -1) - { - return CORBA::ORB::_nil (); - } - - CORBA::ORB::init_orb_globals (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (CORBA::ORB::_nil ()); + { + // Using ACE_Static_Object_Lock::instance() precludes ORB_init() + // from being called within a static object CTOR. + ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, + guard, + *ACE_Static_Object_Lock::instance (), + CORBA::ORB::_nil ())); + + // Make sure TAO's singleton manager is initialized. + if (TAO_Singleton_Manager::instance ()->init () == -1) + { + return CORBA::ORB::_nil (); + } + + TAO::ORB::init_orb_globals (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::ORB::_nil ()); + } // Make sure the following is done after the global ORB // initialization since we need to have exceptions initialized. @@ -1539,17 +1547,23 @@ CORBA::ORB_init (int &argc, } // Get ORB Core - TAO_ORB_Core *oc = - TAO_ORB_Table::instance ()->find (orbid_string.c_str ()); + TAO_ORB_Core_Auto_Ptr oc ( + TAO::ORB_Table::instance ()->find (orbid_string.c_str ())); - // The ORB was initialized already, just return that one! - if (oc != 0) + // The ORB was already initialized. Just return that one. + if (oc.get () != 0) { + ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, + guard, + *ACE_Static_Object_Lock::instance (), + CORBA::ORB::_nil ())); + if (oc->has_shutdown ()) { // As defined by the CORBA 2.3 specification, throw a - // CORBA::BAD_INV_ORDER exception with minor code 4 if the ORB - // has shutdown by the time an ORB function is called. + // CORBA::BAD_INV_ORDER exception with minor code 4 if the + // ORB has shutdown by the time an ORB function is + // called. // @@ Does the BAD_INV_ORDER exception apply here? // -Ossama @@ -1561,28 +1575,31 @@ CORBA::ORB_init (int &argc, return CORBA::ORB::_duplicate (oc->orb ()); } - - // An ORB corresponding to the desired ORBid doesn't exist so create - // a new one. - ACE_NEW_THROW_EX (oc, - TAO_ORB_Core (orbid_string.c_str ()), - CORBA::NO_MEMORY ( - CORBA::SystemException::_tao_minor_code ( - 0, - ENOMEM), - CORBA::COMPLETED_NO)); - ACE_CHECK_RETURN (CORBA::ORB::_nil ()); - - // The ORB table increases the reference count on the ORB Core so do - // not release it here. Allow the TAO_ORB_Core_Auto_Ptr do decrease - // the reference on the ORB Core when it goes out of scope. - TAO_ORB_Core_Auto_Ptr safe_oc (oc); + else + { + // An ORB corresponding to the desired ORBid doesn't exist so create + // a new one. + TAO_ORB_Core * tmp; + ACE_NEW_THROW_EX (tmp, + TAO_ORB_Core (orbid_string.c_str ()), + CORBA::NO_MEMORY ( + CORBA::SystemException::_tao_minor_code (0, + ENOMEM), + CORBA::COMPLETED_NO)); + ACE_CHECK_RETURN (CORBA::ORB::_nil ()); + + // The ORB table increases the reference count on the ORB Core + // so do not release it here. Allow the TAO_ORB_Core_Auto_Ptr + // do decrease the reference on the ORB Core when it goes out of + // scope. + oc.reset (tmp); + } // Initialize the Service Configurator. This must occur before the // ORBInitializer::pre_init() method is invoked on each registered // ORB initializer. - int result = TAO_Internal::open_services (command_line.get_argc (), - command_line.get_TCHAR_argv ()); + int result = TAO::ORB::open_services (command_line.get_argc (), + command_line.get_TCHAR_argv ()); // Check for errors returned from <TAO_Internal::open_services>. if (result != 0 && errno != ENOENT) @@ -1600,9 +1617,9 @@ CORBA::ORB_init (int &argc, } // Run the registered ORB initializers, and initialize the ORB_Core. - TAO_ORBInitInfo *orb_init_info_temp; + TAO_ORBInitInfo * orb_init_info_temp; ACE_NEW_THROW_EX (orb_init_info_temp, - TAO_ORBInitInfo (safe_oc.get (), + TAO_ORBInitInfo (oc.get (), command_line.get_argc(), command_line.get_ASCII_argv()), CORBA::NO_MEMORY ( @@ -1619,14 +1636,14 @@ CORBA::ORB_init (int &argc, // Call the ORBInitializer::pre_init() on each registered ORB // initializer. - TAO_ORBInitializer_Registry::instance ()->pre_init (orb_init_info.in () - ACE_ENV_ARG_PARAMETER); + TAO::ORBInitializer_Registry::instance ()->pre_init (orb_init_info.in () + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (CORBA::ORB::_nil ()); // Initialize the ORB Core instance. - result = safe_oc->init (command_line.get_argc(), - command_line.get_ASCII_argv() - ACE_ENV_ARG_PARAMETER); + result = oc->init (command_line.get_argc(), + command_line.get_ASCII_argv() + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (CORBA::ORB::_nil ()); // Check for errors and return nil pseudo-reference on error. @@ -1640,8 +1657,8 @@ CORBA::ORB_init (int &argc, // Call the ORBInitializer::post_init() on each registered ORB // initializer. - TAO_ORBInitializer_Registry::instance ()->post_init (orb_init_info.in () - ACE_ENV_ARG_PARAMETER); + TAO::ORBInitializer_Registry::instance ()->post_init (orb_init_info.in () + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (CORBA::ORB::_nil ()); #if TAO_HAS_INTERCEPTORS == 1 @@ -1661,8 +1678,8 @@ CORBA::ORB_init (int &argc, } // Before returning remember to store the ORB into the table... - if (TAO_ORB_Table::instance ()->bind (orbid_string.c_str (), - safe_oc.get ()) != 0) + if (TAO::ORB_Table::instance ()->bind (orbid_string.c_str (), + oc.get ()) != 0) ACE_THROW_RETURN (CORBA::INTERNAL (0, CORBA::COMPLETED_NO), CORBA::ORB::_nil ()); diff --git a/TAO/tao/ORB.h b/TAO/tao/ORB.h index b859571e6d1..5a094b44b97 100644 --- a/TAO/tao/ORB.h +++ b/TAO/tao/ORB.h @@ -548,10 +548,6 @@ namespace CORBA /// Resolve the POA. CORBA::Object_ptr resolve_root_poa (ACE_ENV_SINGLE_ARG_DECL); - /// Initialize the ORB globals correctly, i.e., only when they - /// haven't been initialized yet. - static void init_orb_globals (ACE_ENV_SINGLE_ARG_DECL); - // Reference counting... CORBA::ULong _incr_refcnt (void); CORBA::ULong _decr_refcnt (void); @@ -644,13 +640,6 @@ namespace CORBA /// ORB. CORBA::ULong refcount_; - /// Count of the number of times that @c ORB_init() has been - /// called. - /** - * This must be protected by @c ACE_Static_Object_Lock. - */ - static int orb_init_count_; - /// The ORB_Core that created us.... TAO_ORB_Core *orb_core_; @@ -667,6 +656,17 @@ namespace CORBA }; } // End namespace CORBA +namespace TAO +{ + namespace ORB + { + /// Initialize the ORB globals correctly, i.e., only when they + /// haven't been initialized yet. + void init_orb_globals (ACE_ENV_SINGLE_ARG_DECL); + } +} + + #if defined (__ACE_INLINE__) # include "tao/ORB.i" #endif /* __ACE_INLINE__ */ diff --git a/TAO/tao/ORBInitializer_Registry.cpp b/TAO/tao/ORBInitializer_Registry.cpp index c6208e7905b..c6fb209537f 100644 --- a/TAO/tao/ORBInitializer_Registry.cpp +++ b/TAO/tao/ORBInitializer_Registry.cpp @@ -22,49 +22,56 @@ PortableInterceptor::register_orb_initializer ( PortableInterceptor::ORBInitializer_ptr init ACE_ENV_ARG_DECL) { - // Using ACE_Static_Object_Lock::instance() precludes - // <register_orb_initializer> from being called within a static - // object CTOR. - ACE_MT (ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX, - guard, - *ACE_Static_Object_Lock::instance ())); - - // Make sure TAO's singleton manager is initialized. - if (TAO_Singleton_Manager::instance ()->init () == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) register_orb_initializer: ") - ACE_TEXT ("Unable to pre-initialize TAO\n"))); - } - - CORBA::ORB::init_orb_globals (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; + { + // Using ACE_Static_Object_Lock::instance() precludes + // register_orb_initializer() from being called within a static + // object CTOR. + ACE_MT (ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX, + guard, + *ACE_Static_Object_Lock::instance ())); + + // Make sure TAO's singleton manager is initialized. + if (TAO_Singleton_Manager::instance ()->init () == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) register_orb_initializer: ") + ACE_TEXT ("Unable to pre-initialize TAO\n"))); + } + + TAO::ORB::init_orb_globals (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + } // Make sure the following is done after the global ORB // initialization since we need to have exceptions initialized. - TAO_ORBInitializer_Registry::instance ()->register_orb_initializer ( + TAO::ORBInitializer_Registry::instance ()->register_orb_initializer ( init ACE_ENV_ARG_PARAMETER); } // ------------------------------------------------------------------ -TAO_ORBInitializer_Registry::TAO_ORBInitializer_Registry (void) - : initializers_ () +TAO::ORBInitializer_Registry::ORBInitializer_Registry (void) + : lock_ (), + initializers_ () { } void -TAO_ORBInitializer_Registry::register_orb_initializer ( +TAO::ORBInitializer_Registry::register_orb_initializer ( PortableInterceptor::ORBInitializer_ptr init ACE_ENV_ARG_DECL) { if (!CORBA::is_nil (init)) { + ACE_GUARD (TAO_SYNCH_MUTEX, + guard, + this->lock_); + // Increase the length of the ORBInitializer array by one. - const size_t cur_len = this->initializers_.size (); - const size_t new_len = cur_len + 1; + size_t const cur_len = this->initializers_.size (); + size_t const new_len = cur_len + 1; if (this->initializers_.size (new_len) != 0) ACE_THROW (CORBA::INTERNAL ()); @@ -81,11 +88,15 @@ TAO_ORBInitializer_Registry::register_orb_initializer ( } void -TAO_ORBInitializer_Registry::pre_init ( +TAO::ORBInitializer_Registry::pre_init ( PortableInterceptor::ORBInitInfo_ptr info ACE_ENV_ARG_DECL) { - const size_t initializer_count = this->initializers_.size (); + ACE_GUARD (TAO_SYNCH_MUTEX, + guard, + this->lock_); + + size_t const initializer_count (this->initializers_.size ()); for (size_t i = 0; i < initializer_count; ++i) { this->initializers_[i]->pre_init (info @@ -95,11 +106,15 @@ TAO_ORBInitializer_Registry::pre_init ( } void -TAO_ORBInitializer_Registry::post_init ( +TAO::ORBInitializer_Registry::post_init ( PortableInterceptor::ORBInitInfo_ptr info ACE_ENV_ARG_DECL) { - const size_t initializer_count = this->initializers_.size (); + ACE_GUARD (TAO_SYNCH_MUTEX, + guard, + this->lock_); + + size_t const initializer_count (this->initializers_.size ()); for (size_t i = 0; i < initializer_count; ++i) { this->initializers_[i]->post_init (info @@ -108,25 +123,25 @@ TAO_ORBInitializer_Registry::post_init ( } } -TAO_ORBInitializer_Registry * -TAO_ORBInitializer_Registry::instance (void) +TAO::ORBInitializer_Registry * +TAO::ORBInitializer_Registry::instance (void) { return - TAO_Singleton<TAO_ORBInitializer_Registry, TAO_SYNCH_MUTEX>::instance (); + TAO_Singleton<TAO::ORBInitializer_Registry, TAO_SYNCH_MUTEX>::instance (); } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class TAO_Singleton<TAO_ORBInitializer_Registry, TAO_SYNCH_MUTEX>; +template class TAO_Singleton<TAO::ORBInitializer_Registry, TAO_SYNCH_MUTEX>; template class ACE_Array_Base<PortableInterceptor::ORBInitializer_var>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate TAO_Singleton<TAO_ORBInitializer_Registry, TAO_SYNCH_MUTEX> +#pragma instantiate TAO_Singleton<TAO::ORBInitializer_Registry, TAO_SYNCH_MUTEX> #pragma instantiate ACE_Array_Base<PortableInterceptor::ORBInitializer_var> #elif defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) -template TAO_Singleton<TAO_ORBInitializer_Registry, TAO_SYNCH_MUTEX> * TAO_Singleton<TAO_ORBInitializer_Registry, TAO_SYNCH_MUTEX>::singleton_; +template TAO_Singleton<TAO::ORBInitializer_Registry, TAO_SYNCH_MUTEX> * TAO_Singleton<TAO_ORBInitializer_Registry, TAO_SYNCH_MUTEX>::singleton_; #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/ORBInitializer_Registry.h b/TAO/tao/ORBInitializer_Registry.h index 7ca80da1c2a..e20773440a7 100644 --- a/TAO/tao/ORBInitializer_Registry.h +++ b/TAO/tao/ORBInitializer_Registry.h @@ -24,6 +24,8 @@ #include "Objref_VarOut_T.h" #include "Environment.h" +#include "ace/Thread_Mutex.h" + namespace PortableInterceptor { class ORBInitializer; @@ -46,71 +48,77 @@ namespace PortableInterceptor ); } -/** - * @class TAO_ORBInitializer_Registry - * - * @brief Global list that contains all portable interceptor ORB - * initializers. - * - * @note This class should be instantiated via its instance() method. - * Normally this would be enforced by making the constructor - * protected but that forces a friend declaration containing a - * template type (TAO_Singleton) with a static member to be - * introduced. In turn, this potentially introduces problems in - * MS Windows DLL environments due to the occurance of multiple - * singleton instances. There should only be one! - */ -class TAO_ORBInitializer_Registry +namespace TAO { - friend void PortableInterceptor::register_orb_initializer ( + /** + * @class ORBInitializer_Registry + * + * @brief Global list that contains all portable interceptor ORB + * initializers. + * + * @note This class should be instantiated via its instance() + * method. Normally this would be enforced by making the + * constructor protected but that forces a friend declaration + * containing a template type (TAO_Singleton) with a static + * member to be introduced. In turn, this potentially + * introduces problems in MS Windows DLL environments due to + * the occurance of multiple singleton instances. There + * should only be one! + */ + class ORBInitializer_Registry + { + friend void PortableInterceptor::register_orb_initializer ( PortableInterceptor::ORBInitializer_ptr init ACE_ENV_ARG_DECL); - friend CORBA::ORB_ptr CORBA::ORB_init (int &, - char *argv[], - const char *, - CORBA::Environment &); + friend CORBA::ORB_ptr CORBA::ORB_init (int &, + char *argv[], + const char *, + CORBA::Environment &); -public: - /// Only allow this class to be instantiated as a singleton - /// instance, so declare the constructor as protected. - /** - * @note See the note in the class description for an explanation of - * why this constructor is not protected. - */ - TAO_ORBInitializer_Registry (void); - -protected: - /// Register an ORBInitializer with the underlying ORBInitializer - /// array. - void register_orb_initializer ( - PortableInterceptor::ORBInitializer_ptr init - ACE_ENV_ARG_DECL); - - /// Begin initialization of all registered ORBInitializers before - /// the ORB itself is initialized. - void pre_init (PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL); - - /// Complete initialization of all registered ORBInitializers after - /// the ORB has been initialized. - void post_init (PortableInterceptor::ORBInitInfo_ptr info - ACE_ENV_ARG_DECL); + public: + + /// Only allow this class to be instantiated as a singleton + /// instance, so declare the constructor as protected. + /** + * @note See the note in the class description for an explanation of + * why this constructor is not protected. + */ + ORBInitializer_Registry (void); + + protected: + + /// Register an ORBInitializer with the underlying ORBInitializer + /// array. + void register_orb_initializer (PortableInterceptor::ORBInitializer_ptr init + ACE_ENV_ARG_DECL); - /// Return a unique singleton instance. - static TAO_ORBInitializer_Registry *instance (void); + /// Begin initialization of all registered ORBInitializers before + /// the ORB itself is initialized. + void pre_init (PortableInterceptor::ORBInitInfo_ptr info + ACE_ENV_ARG_DECL); -private: - /// Prevent copying - ACE_UNIMPLEMENTED_FUNC ( - TAO_ORBInitializer_Registry (const TAO_ORBInitializer_Registry &)) - ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_ORBInitializer_Registry &)) + /// Complete initialization of all registered ORBInitializers after + /// the ORB has been initialized. + void post_init (PortableInterceptor::ORBInitInfo_ptr info + ACE_ENV_ARG_DECL); -private: + /// Return a unique singleton instance. + static ORBInitializer_Registry * instance (void); - /// Dynamic array containing registered ORBInitializers. - ACE_Array_Base<PortableInterceptor::ORBInitializer_var> initializers_; -}; + private: + // Prevent copying + ORBInitializer_Registry (const ORBInitializer_Registry &); + void operator= (const ORBInitializer_Registry &); + + private: + + TAO_SYNCH_MUTEX lock_; + + /// Dynamic array containing registered ORBInitializers. + ACE_Array_Base<PortableInterceptor::ORBInitializer_var> initializers_; + }; +} #include /**/ "ace/post.h" diff --git a/TAO/tao/ORB_Core.cpp b/TAO/tao/ORB_Core.cpp index 8593c21c13f..d5f61469f9c 100644 --- a/TAO/tao/ORB_Core.cpp +++ b/TAO/tao/ORB_Core.cpp @@ -312,21 +312,27 @@ TAO_ORB_Core::init (int &argc, char *argv[] ACE_ENV_ARG_DECL) int std_profile_components = 0; #endif /* TAO_STD_PROFILE_COMPONENTS */ + // Copy command line parameter not to use original. + ACE_Argv_Type_Converter command_line (argc, argv); + + ACE_Arg_Shifter arg_shifter (command_line.get_argc (), + command_line.get_TCHAR_argv ()); + + ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, + monitor, + this->lock_, + -1); + // Pick up the value of the use_implrepo_ flag from an environment variable // called "TAO_USE_IMR". Do it here so that it can be overridden by // the "-ORBUseIMR" command line argument. // - char* use_IMR_env_var_value = ACE_OS::getenv ("TAO_USE_IMR") ; + char* const use_IMR_env_var_value = ACE_OS::getenv ("TAO_USE_IMR") ; if (use_IMR_env_var_value != 0) { this->use_implrepo_ = ACE_OS::atoi (use_IMR_env_var_value) ; } - // Copy command line parameter not to use original. - ACE_Argv_Type_Converter command_line(argc, argv); - - ACE_Arg_Shifter arg_shifter (command_line.get_argc(), - command_line.get_TCHAR_argv()); while (arg_shifter.is_anything_left ()) { @@ -1185,7 +1191,7 @@ TAO_ORB_Core::fini (void) if (this->thread_lane_resources_manager_ != 0) this->thread_lane_resources_manager_->finalize (); - (void) TAO_Internal::close_services (); + (void) TAO::ORB::close_services (); // Destroy the object_key table this->object_key_table_.destroy (); @@ -1682,16 +1688,14 @@ TAO_ORB_Core::create_object (TAO_Stub *stub) // but we are stuck in platforms without exceptions! CORBA::Object_ptr x; { - // @@ Ossama: maybe we need another lock for the table, to - // reduce contention on the Static_Object_Lock below, if so - // then we need to use that lock in the ORB_init() function. - ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, - *ACE_Static_Object_Lock::instance (), - 0)); - - TAO_ORB_Table *table = TAO_ORB_Table::instance (); - const TAO_ORB_Table::Iterator end = table->end (); - for (TAO_ORB_Table::Iterator i = table->begin (); i != end; ++i) + ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, + guard, + this->lock_, + CORBA::Object::_nil ()); + + TAO::ORB_Table * const table = TAO::ORB_Table::instance (); + const TAO::ORB_Table::Iterator end = table->end (); + for (TAO::ORB_Table::Iterator i = table->begin (); i != end; ++i) { TAO_ORB_Core *other_core = (*i).int_id_; @@ -1727,20 +1731,21 @@ TAO_ORB_Core::initialize_object (TAO_Stub *stub, // @@ Ossama: maybe we need another lock for the table, to // reduce contention on the Static_Object_Lock below, if so // then we need to use that lock in the ORB_init() function. - ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, - *ACE_Static_Object_Lock::instance (), + ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, + guard, + this->lock_, 0)); - TAO_ORB_Table *table = TAO_ORB_Table::instance (); - TAO_ORB_Table::Iterator end = table->end (); - for (TAO_ORB_Table::Iterator i = table->begin (); i != end; ++i) + TAO::ORB_Table * const table = TAO::ORB_Table::instance (); + TAO::ORB_Table::Iterator const end = table->end (); + for (TAO::ORB_Table::Iterator i = table->begin (); i != end; ++i) { - TAO_ORB_Core *other_core = (*i).int_id_; + TAO_ORB_Core * const other_core = (*i).int_id_; if (this->is_collocation_enabled (other_core, mprofile)) { - TAO_Adapter_Registry *ar = + TAO_Adapter_Registry * const ar = other_core->adapter_registry (); return ar->initialize_collocated_object (stub, @@ -2008,11 +2013,7 @@ TAO_ORB_Core::destroy (ACE_ENV_SINGLE_ARG_DECL) // Now remove it from the ORB table so that it's ORBid may be // reused. - { - ACE_MT (ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX, guard, - *ACE_Static_Object_Lock::instance ())); - TAO_ORB_Table::instance ()->unbind (this->orbid_); - } + TAO::ORB_Table::instance ()->unbind (this->orbid_); } void @@ -2829,7 +2830,7 @@ TAO_ORB_Core_instance (void) { // @@ This is a slight violation of layering, we should use // TAO_ORB_Core_instance(), but that breaks during startup. - TAO_ORB_Table *orb_table = TAO_ORB_Table::instance (); + TAO::ORB_Table * const orb_table = TAO::ORB_Table::instance (); if (orb_table->first_orb () == 0) { ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, @@ -2913,16 +2914,16 @@ TAO_ORB_Core::init_ref_map () } void -TAO_ORB_Core::set_default (const char *orb_id) +TAO_ORB_Core::set_default (const char * orb_id) { - TAO_ORB_Table *table = TAO_ORB_Table::instance (); + TAO::ORB_Table * const table = TAO::ORB_Table::instance (); table->set_default (orb_id); } void -TAO_ORB_Core::not_default (const char *orb_id) +TAO_ORB_Core::not_default (const char * orb_id) { - TAO_ORB_Table *table = TAO_ORB_Table::instance (); + TAO::ORB_Table * const table = TAO::ORB_Table::instance (); table->not_default (orb_id); } diff --git a/TAO/tao/ORB_Table.cpp b/TAO/tao/ORB_Table.cpp index 5045df1f7a4..a678a26da19 100644 --- a/TAO/tao/ORB_Table.cpp +++ b/TAO/tao/ORB_Table.cpp @@ -16,8 +16,9 @@ ACE_RCSID (tao, // **************************************************************** -TAO_ORB_Table::TAO_ORB_Table (void) - : first_orb_not_default_ (0), +TAO::ORB_Table::ORB_Table (void) + : lock_ (), + first_orb_not_default_ (false), table_ (TAO_DEFAULT_ORB_TABLE_SIZE), first_orb_ (0), orbs_ (0), @@ -25,10 +26,10 @@ TAO_ORB_Table::TAO_ORB_Table (void) { } -TAO_ORB_Table::~TAO_ORB_Table (void) +TAO::ORB_Table::~ORB_Table (void) { - const Iterator end = this->end (); - for (Iterator i = this->begin (); i != end; ++i) + Iterator const end (this->end ()); + for (Iterator i (this->begin ()); i != end; ++i) { // Deallocate the ORBid. CORBA::string_free (const_cast<char *> ((*i).ext_id_)); @@ -40,28 +41,28 @@ TAO_ORB_Table::~TAO_ORB_Table (void) this->table_.close (); } -TAO_ORB_Table::Iterator -TAO_ORB_Table::begin (void) +TAO::ORB_Table::Iterator +TAO::ORB_Table::begin (void) { return this->table_.begin (); } -TAO_ORB_Table::Iterator -TAO_ORB_Table::end (void) +TAO::ORB_Table::Iterator +TAO::ORB_Table::end (void) { return this->table_.end (); } TAO_ORB_Core* const * -TAO_ORB_Table::get_orbs (size_t& num_orbs) +TAO::ORB_Table::get_orbs (size_t& num_orbs) { num_orbs = this->num_orbs_; return this->orbs_; } int -TAO_ORB_Table::bind (const char *orb_id, - TAO_ORB_Core *orb_core) +TAO::ORB_Table::bind (char const * orb_id, + TAO_ORB_Core * orb_core) { // Make sure that the supplied ORB core pointer is valid, // i.e. non-zero. @@ -71,8 +72,14 @@ TAO_ORB_Table::bind (const char *orb_id, return -1; }; - CORBA::String_var id = CORBA::string_dup (orb_id); - int result = this->table_.bind (id.in (), orb_core); + CORBA::String_var id (CORBA::string_dup (orb_id)); + + ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, + guard, + this->lock_, + -1); + + int const result = this->table_.bind (id.in (), orb_core); if (result == 0) { @@ -104,17 +111,34 @@ TAO_ORB_Table::bind (const char *orb_id, } TAO_ORB_Core * -TAO_ORB_Table::find (const char *orb_id) +TAO::ORB_Table::find (char const * orb_id) { - TAO_ORB_Core *found = 0; + TAO_ORB_Core * found = 0; + + ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, + guard, + this->lock_, + 0); + this->table_.find (orb_id, found); + + // Maintain ownership of the ORB_Core. + if (found != 0) + (void) found->_incr_refcnt (); + return found; } int -TAO_ORB_Table::unbind (const char *orb_id) +TAO::ORB_Table::unbind (const char *orb_id) { - Table::ENTRY *entry = 0; + Table::ENTRY * entry = 0; + + ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, + guard, + this->lock_, + -1); + int result = this->table_.find (orb_id, entry); if (result == 0) @@ -123,7 +147,7 @@ TAO_ORB_Table::unbind (const char *orb_id) // before unbinding the entry since the entry is deallocated // during the call to unbind(). CORBA::string_free (const_cast<char *> (entry->ext_id_)); - TAO_ORB_Core *orb_core = entry->int_id_; + TAO_ORB_Core * const orb_core = entry->int_id_; result = this->table_.unbind (entry); @@ -134,8 +158,8 @@ TAO_ORB_Table::unbind (const char *orb_id) if (orb_core == this->first_orb_) { - Iterator begin = this->begin (); - Iterator end = this->end (); + Iterator const begin (this->begin ()); + Iterator const end (this->end ()); if (begin != end) { @@ -154,22 +178,31 @@ TAO_ORB_Table::unbind (const char *orb_id) } void -TAO_ORB_Table::set_default (const char *orb_id) +TAO::ORB_Table::set_default (char const * orb_id) { + ACE_GUARD (TAO_SYNCH_MUTEX, + guard, + this->lock_); + this->table_.find (orb_id, this->first_orb_); } void -TAO_ORB_Table::not_default (const char *orb_id) +TAO::ORB_Table::not_default (char const * orb_id) { // @@ This method now works for restricted cases. Should work on - // generalizing it. It works if the first ORB that is registered - // decides to not want be the default ORB. Should generalize it to - // handle all cases. + // generalizing it. It works if the first ORB that is registered + // decides to not want be the default ORB. Should generalize it + // to handle all cases. + + + ACE_GUARD (TAO_SYNCH_MUTEX, + guard, + this->lock_); - //check if there is a default ORB already and if - // it is *not* the same as the orb_id thats passed in.. we dont have - // to do anything. + // Check if there is a default ORB already and if it is *not* the + // same as the orb_id thats passed in. We don't have to do + // anything. if (this->first_orb_ != 0) { if (ACE_OS::strcmp (this->first_orb_->orbid (), orb_id) != 0) @@ -181,28 +214,28 @@ TAO_ORB_Table::not_default (const char *orb_id) { // The ORB with orbid 'orb_id' is the default now. We need // to change it. - this->first_orb_not_default_ = 1; + this->first_orb_not_default_ = true; } } } /// Accessor to the underlying table_ -ACE_Hash_Map_Manager_Ex<const char *,TAO_ORB_Core *,ACE_Hash<const char *>,ACE_Equal_To<const char *>,ACE_Null_Mutex> * -TAO_ORB_Table::table (void) +TAO::ORB_Table::Table * +TAO::ORB_Table::table (void) { return &this->table_; } -TAO_ORB_Table * -TAO_ORB_Table::instance (void) +TAO::ORB_Table * +TAO::ORB_Table::instance (void) { - return TAO_Singleton<TAO_ORB_Table, TAO_SYNCH_MUTEX>::instance (); + return TAO_Singleton<TAO::ORB_Table, TAO_SYNCH_MUTEX>::instance (); } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class TAO_Singleton<TAO_ORB_Table,TAO_SYNCH_MUTEX>; +template class TAO_Singleton<TAO::ORB_Table,TAO_SYNCH_MUTEX>; template class ACE_Hash_Map_Entry<const char *, TAO_ORB_Core *>; template class ACE_Hash_Map_Manager_Ex<const char *, TAO_ORB_Core *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, ACE_Null_Mutex>; @@ -212,7 +245,7 @@ template class ACE_Hash_Map_Reverse_Iterator_Ex<const char *, TAO_ORB_Core *, AC #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate TAO_Singleton<TAO_ORB_Table,TAO_SYNCH_MUTEX> +#pragma instantiate TAO_Singleton<TAO::ORB_Table,TAO_SYNCH_MUTEX> #pragma instantiate ACE_Hash_Map_Entry<const char *, TAO_ORB_Core *> #pragma instantiate ACE_Hash_Map_Manager_Ex<const char *, TAO_ORB_Core *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, ACE_Null_Mutex> @@ -222,6 +255,6 @@ template class ACE_Hash_Map_Reverse_Iterator_Ex<const char *, TAO_ORB_Core *, AC #elif defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) -template TAO_Singleton<TAO_ORB_Table,TAO_SYNCH_MUTEX> * TAO_Singleton<TAO_ORB_Table,TAO_SYNCH_MUTEX>::singleton_; +template TAO_Singleton<TAO::ORB_Table,TAO_SYNCH_MUTEX> * TAO_Singleton<TAO::ORB_Table,TAO_SYNCH_MUTEX>::singleton_; #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/ORB_Table.h b/TAO/tao/ORB_Table.h index 97a37403fe2..30eca509c82 100644 --- a/TAO/tao/ORB_Table.h +++ b/TAO/tao/ORB_Table.h @@ -23,101 +23,123 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/orbconf.h" + #include "ace/Hash_Map_Manager_T.h" +#include "ace/Thread_Mutex.h" #include "ace/Null_Mutex.h" + // Forward declarations. class TAO_ORB_Core; -/** - * @class TAO_ORB_Table - * - * @brief Keep a table with all the ORBs in the system. - * - * CORBA::ORB_init() is supposed to return the same ORB if the - * user specifies the same ORBid, either in the ORB_init() - * parameter or in the -ORBid option. - * This class is used to implement that feature. - * It is also useful when trying to determine if an object - * reference is collocated or not. - * - * @note This class should be instantiated via its instance() method. - * Normally this would be enforced by making the constructor - * protected but that forces a friend declaration containing a - * template type (TAO_Singleton) with a static member to be - * introduced. In turn, this potentially introduces problems in - * MS Windows DLL environments due to the occurance of multiple - * singleton instances. There should only be one! - */ -class TAO_Export TAO_ORB_Table +namespace TAO { -public: - - /// Constructor /** - * @note See the note in the class description for an explanation of - * why this constructor is not protected. + * @class ORB_Table + * + * @brief Keep a table with all the ORBs in the system. + * + * CORBA::ORB_init() is supposed to return the same ORB if the + * user specifies the same ORBid, either in the ORB_init() + * parameter or in the -ORBid option. + * This class is used to implement that feature. + * It is also useful when trying to determine if an object + * reference is collocated or not. + * + * @note This class should be instantiated via its instance() + * method. Normally this would be enforced by making the + * constructor protected but that forces a friend declaration + * containing a template type (TAO_Singleton) with a static + * member to be introduced. In turn, this potentially + * introduces problems in MS Windows DLL environments due to + * the occurance of multiple singleton instances. There + * should only be one! */ - TAO_ORB_Table (void); + class TAO_Export ORB_Table + { + public: + + /// Constructor + /** + * @note See the note in the class description for an explanation + * of why this constructor is not protected. + */ + ORB_Table (void); + + /// destructor + ~ORB_Table (void); + + typedef ACE_Hash_Map_Manager_Ex<const char *, TAO_ORB_Core *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, ACE_Null_Mutex> Table; + typedef Table::iterator Iterator; + + /// The canonical ACE_Map methods. + //@{ + Iterator begin (void); + Iterator end (void); + int bind (const char *orb_id, TAO_ORB_Core *orb_core); + + /** + * @note The caller must decrease the reference count on the + * returned ORB_Core, i.e. the callers "owns" it. + */ + TAO_ORB_Core* find (const char *orb_id); + + int unbind (const char *orb_id); + //@} - /// destructor - ~TAO_ORB_Table (void); + TAO_ORB_Core * const * get_orbs (size_t& num_orbs); - typedef ACE_Hash_Map_Manager_Ex<const char *, TAO_ORB_Core *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, ACE_Null_Mutex> Table; - typedef Table::iterator Iterator; + /// Obtain the first ORB for the @c ORB_Core_instance() + /// implementation. + TAO_ORB_Core * first_orb (void); - /// The canonical ACE_Map methods. - //@{ - Iterator begin (void); - Iterator end (void); - int bind (const char *orb_id, TAO_ORB_Core *orb_core); - TAO_ORB_Core* find (const char *orb_id); - int unbind (const char *orb_id); - TAO_ORB_Core* const * get_orbs( size_t& num_orbs ); - //@} + /// Return a unique instance + static ORB_Table * instance (void); - /// Obtain the first ORB for the ORB_Core_instance() implementation - TAO_ORB_Core *first_orb (void); + /// Set the ORB related to the orb_id as the default ORB and not the + /// ORB that is first binded. + void set_default (char const * orb_id); - /// Return a unique instance - static TAO_ORB_Table *instance (void); + /// Method the ORB invokes to specify that it doesnt want to be the + /// default ORB if there are more than one ORB registered. + void not_default (char const * orb_id); - /// Set the ORB related to the orb_id as the default ORB and not the - /// ORB that is first binded. - void set_default (const char *orb_id); + /// Accessor to the underlying table_ + Table * table (void); - /// Method the ORB invokes to specify that it doesnt want to be the - /// default ORB if there are more than one ORB registered. - void not_default (const char *orb_id); + private: - /// Accessor to the underlying table_ - Table * table (void); + // Prevent copying + ORB_Table (const ORB_Table &); + void operator= (const ORB_Table &); -private: + /// Update our list of orbs + void update_orbs (void); - /// Prevent copying - ACE_UNIMPLEMENTED_FUNC (TAO_ORB_Table (const TAO_ORB_Table &)) - ACE_UNIMPLEMENTED_FUNC (void operator= (const TAO_ORB_Table &)) + private: -private: + /// Lock used to synchronize access to the internal state. + TAO_SYNCH_MUTEX lock_; - /// Update our list of orbs - void update_orbs(); + /// Variable to check if the first ORB decides not to be the + /// default. + bool first_orb_not_default_; - /// Variable to check if the first ORB decides not to be the default - bool first_orb_not_default_; + /// The underlying table. + Table table_; - /// The implementation. - Table table_; + /// The first ORB created by the user + TAO_ORB_Core * first_orb_; - /// The first ORB created by the user - TAO_ORB_Core *first_orb_; + /// List of orbs for get_orbs call + TAO_ORB_Core ** orbs_; - /// List of orbs for get_orbs call - TAO_ORB_Core **orbs_; - size_t num_orbs_; + /// Number of ORBs in the table. + size_t num_orbs_; -}; + }; +} #if defined (__ACE_INLINE__) # include "tao/ORB_Table.inl" diff --git a/TAO/tao/ORB_Table.inl b/TAO/tao/ORB_Table.inl index f1aedccc4df..f8f1f2d9937 100644 --- a/TAO/tao/ORB_Table.inl +++ b/TAO/tao/ORB_Table.inl @@ -3,7 +3,7 @@ // $Id$ ACE_INLINE TAO_ORB_Core * -TAO_ORB_Table::first_orb (void) +TAO::ORB_Table::first_orb (void) { return this->first_orb_; } diff --git a/TAO/tao/TAO_Internal.cpp b/TAO/tao/TAO_Internal.cpp index 89def4edd24..c1e6ffe1497 100644 --- a/TAO/tao/TAO_Internal.cpp +++ b/TAO/tao/TAO_Internal.cpp @@ -25,7 +25,7 @@ #include "ace/Argv_Type_Converter.h" #include "ace/Env_Value_T.h" #include "ace/ACE.h" -#include "ace/Static_Object_Lock.h" +#include "ace/Atomic_Op.h" #include "ace/OS_NS_stdio.h" @@ -34,37 +34,62 @@ ACE_RCSID (tao, "$Id$") -#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) && \ - defined (TAO_DEFAULT_RESOURCE_FACTORY_ARGS) -const char *TAO_Internal::resource_factory_args_ = - TAO_DEFAULT_RESOURCE_FACTORY_ARGS; -#else -const char *TAO_Internal::resource_factory_args_ = 0; -#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP && - TAO_DEFAULT_RESOURCE_FACTORY_ARGS */ - -#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) && \ - defined (TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS) -const char *TAO_Internal::server_strategy_factory_args_ = - TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS; -#else -const char *TAO_Internal::server_strategy_factory_args_ = 0; -#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP && - TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS */ - -#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) && \ - defined (TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS) -const char *TAO_Internal::client_strategy_factory_args_ = - TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS; -#else -const char *TAO_Internal::client_strategy_factory_args_ = 0; -#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP && - TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS */ - -int TAO_Internal::service_open_count_ = 0; +#ifndef TAO_DEFAULT_RESOURCE_FACTORY_ARGS +# define TAO_DEFAULT_RESOURCE_FACTORY_ARGS 0 +#endif /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */ + +#ifndef TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS +# define TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS 0 +#endif /* !TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS */ + +#ifndef TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS +# define TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS 0 +#endif /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */ + + +namespace +{ + /** + * Initialize the ACE Service Configurator. This is a one-shot + * method, i.e., it can be called multiple times but it will only do + * its work once. It does, however, track the number of times it's + * called (see @c open_services()). It is fully thread-safe. + * + * @return @c 0 if successful, @c -1 with @c errno set if failure. + * + * @note You can provide your program a set of default `svc.conf' + * entries by setting @a ignore_default_svc_conf_file to + * non-zero and use @c default_svc_conf_entries() before + * calling @c open_services(). In addition, you can @a + * skip_service_config_open altogether, which used to be + * important when the ORB is linked in via the + * ACE_Service_Configurator, since the + * ACE_Service_Configurator was non-reentrant. However, the + * ACE_Service_Configurator is now reentrant meaning that it + * is really no longer necessary to do so. + */ + int open_services_i (int & argc, + char ** argv, + bool ignore_default_svc_conf_file = false, + bool skip_service_config_open = false); + + /// Number of times open_services() has been called. Incremented by + /// open_services(), and decremented by close_services(). + /** + * @note In/decrement operations are atomic. + */ + ACE_Atomic_Op<TAO_SYNCH_MUTEX, long> service_open_count (0); + + char const * resource_factory_args = + TAO_DEFAULT_RESOURCE_FACTORY_ARGS; + char const * server_strategy_factory_args = + TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS; + char const * client_strategy_factory_args = + TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS; +} int -TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) +TAO::ORB::open_services (int &argc, ACE_TCHAR **argv) { // Construct an argument vector specific to the Service // Configurator. @@ -72,27 +97,31 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) // Be certain to copy the program name so that service configurator // has something to skip! - ACE_CString argv0 = ""; + ACE_CString argv0 (""); if (argc > 0 && argv != 0) { - argv0 = ACE_TEXT_ALWAYS_CHAR(argv[0]); + argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]); } CORBA::ULong len = 0; svc_config_argv.length (1); svc_config_argv[0] = argv0.c_str (); - // Should we skip the <ACE_Service_Config::open> method, e.g., if we + // Should we skip the ACE_Service_Config::open() method, e.g., if we // already being configured by the ACE Service Configurator. - int skip_service_config_open = 0; + // + // @@ This is no longer needed since the Service Configurator is + // now reentrant. + // -Ossama + bool skip_service_config_open = false; #if defined (TAO_DEBUG) && !defined (ACE_HAS_WINCE) // Make it a little easier to debug programs using this code. { TAO_debug_level = ACE_Env_Value<u_int> ("TAO_ORB_DEBUG", 0); - char *value = ACE_OS::getenv ("TAO_ORB_DEBUG"); + char * const value = ACE_OS::getenv ("TAO_ORB_DEBUG"); if (value != 0) { @@ -104,7 +133,8 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) } ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO_debug_level == %d\n"), TAO_debug_level)); + ACE_TEXT ("TAO_debug_level == %d\n"), + TAO_debug_level)); } } #endif /* TAO_DEBUG && !ACE_HAS_WINCE */ @@ -119,13 +149,13 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) // Start with the parameterless flags. if (arg_shifter.cur_arg_strncasecmp - (ACE_TEXT("-ORBSkipServiceConfigOpen")) == 0) + (ACE_TEXT ("-ORBSkipServiceConfigOpen")) == 0) { - skip_service_config_open = 1; + skip_service_config_open = true; arg_shifter.consume_arg (); } - else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ORBDebug")) == 0) + else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBDebug")) == 0) { // later, replace all of these // warning this turns on a daemon @@ -133,14 +163,14 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) arg_shifter.consume_arg (); } else if ((current_arg = arg_shifter.get_the_parameter - (ACE_TEXT("-ORBDebugLevel")))) + (ACE_TEXT ("-ORBDebugLevel")))) { TAO_debug_level = ACE_OS::atoi (current_arg); arg_shifter.consume_arg (); } - else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ORBDaemon")) == 0) + else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBDaemon")) == 0) { // Be a daemon @@ -152,7 +182,7 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) arg_shifter.consume_arg (); } // Continue with flags that accept parameters. - else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ORBSvcConfDirective")))) + else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConfDirective")))) { len = svc_config_argv.length (); svc_config_argv.length (len + 2); // 2 arguments to add @@ -166,12 +196,12 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) arg_shifter.consume_arg (); } - else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ORBSvcConf")))) + else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConf")))) { // Specify the name of the svc.conf file to be used. // Proceeds only if the configuration file exists. - FILE *conf_file = ACE_OS::fopen (current_arg, ACE_TEXT("r")); + FILE * const conf_file = ACE_OS::fopen (current_arg, ACE_TEXT ("r")); if (conf_file == 0) { @@ -200,7 +230,7 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) arg_shifter.consume_arg(); } - else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ORBServiceConfigLoggerKey")))) + else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ORBServiceConfigLoggerKey")))) { len = svc_config_argv.length (); svc_config_argv.length (len + 2); // 2 arguments to add @@ -220,86 +250,92 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv) } int svc_config_argc = svc_config_argv.length (); - return TAO_Internal::open_services_i (svc_config_argc, - svc_config_argv.get_buffer (), - 0, // @@ What about this argument? - skip_service_config_open); + return open_services_i (svc_config_argc, + svc_config_argv.get_buffer (), + 0, // @@ What about this argument? + skip_service_config_open); } +int +TAO::ORB::close_services (void) +{ + --service_open_count; // Atomic! + + return 0; +} void -TAO_Internal::default_svc_conf_entries (const char *resource_factory_args, - const char *server_strategy_factory_args, - const char *client_strategy_factory_args) +TAO::ORB::default_svc_conf_entries (char const * rf_args, + char const * ssf_args, + char const * csf_args) { - TAO_Internal::resource_factory_args_ = resource_factory_args; - TAO_Internal::server_strategy_factory_args_ = server_strategy_factory_args; - TAO_Internal::client_strategy_factory_args_ = client_strategy_factory_args; + resource_factory_args = rf_args; + server_strategy_factory_args = ssf_args; + client_strategy_factory_args = csf_args; } -int -TAO_Internal::open_services_i (int &argc, - char **argv, - int ignore_default_svc_conf_file, - int skip_service_config_open) +// ----------------------------------------------------- +namespace { - ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, - guard, *ACE_Static_Object_Lock::instance (), - -1)); - + int + open_services_i (int & argc, + char ** argv, + bool ignore_default_svc_conf_file, + bool skip_service_config_open) + { #if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) - ignore_default_svc_conf_file = 1; + ignore_default_svc_conf_file = true; #endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP */ - if (TAO_Internal::service_open_count_++ == 0) - { - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Resource_Factory); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Client_Strategy_Factory); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Server_Strategy_Factory); - - // Configure the IIOP factory. You do *NOT* - // need modify this code to add your own protocol, instead - // simply add the following to your svc.conf file: - // - // dynamic PN_Factory Service_Object * LIB:_make_PN_Protocol_Factory() "" - // static Resource_Factory "-ORBProtocolFactory PN_Factory" - // - // where PN is the name of your protocol and LIB is the base - // name of the shared library that implements the protocol. - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_IIOP_Protocol_Factory); - - // add descriptor to list of static objects. - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_MCAST_Parser); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_CORBANAME_Parser); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_CORBALOC_Parser); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_FILE_Parser); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_DLL_Parser); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Stub_Factory); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Endpoint_Selector_Factory); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Protocols_Hooks); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Thread_Lane_Resources_Manager_Factory); - ACE_Service_Config::process_directive ( - ace_svc_desc_TAO_Default_Collocation_Resolver); - - int result = 0; - - if (skip_service_config_open == 0) - { + if (service_open_count++ == 0) // Atomic increment + { + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Resource_Factory); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Client_Strategy_Factory); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Server_Strategy_Factory); + + // Configure the IIOP factory. You do *NOT* need modify this + // code to add your own protocol, instead simply add the + // following to your svc.conf file: + // + // dynamic PN_Factory Service_Object * LIB:_make_PN_Protocol_Factory() "" + // static Resource_Factory "-ORBProtocolFactory PN_Factory" + // + // where PN is the name of your protocol and LIB is the base + // name of the shared library that implements the protocol. + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_IIOP_Protocol_Factory); + + // add descriptor to list of static objects. + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_MCAST_Parser); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_CORBANAME_Parser); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_CORBALOC_Parser); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_FILE_Parser); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_DLL_Parser); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Stub_Factory); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Endpoint_Selector_Factory); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Protocols_Hooks); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Thread_Lane_Resources_Manager_Factory); + ACE_Service_Config::process_directive ( + ace_svc_desc_TAO_Default_Collocation_Resolver); + + int result = 0; + + if (!skip_service_config_open) + { // Copy command line parameter not to use original. - ACE_Argv_Type_Converter command_line(argc, argv); + ACE_Argv_Type_Converter command_line (argc, argv); result = ACE_Service_Config::open (command_line.get_argc(), @@ -307,110 +343,78 @@ TAO_Internal::open_services_i (int &argc, ACE_DEFAULT_LOGGER_KEY, 0, // Don't ignore static services. ignore_default_svc_conf_file); - } - - // If available, allow the Adapter Factory to setup. - ACE_Service_Object *adapter_factory = - ACE_Dynamic_Service<TAO_Adapter_Factory>::instance ( - TAO_ORB_Core::poa_factory_name ().c_str() - ); - - if (adapter_factory != 0) - { - adapter_factory->init (0, 0); - } + } - // Handle RTCORBA library special case. Since RTCORBA needs - // its init method call to register several hooks, call it here - // if it hasn't already been called. - ACE_Service_Object *rt_loader = - ACE_Dynamic_Service<ACE_Service_Object>::instance ("RT_ORB_Loader"); + // If available, allow the Adapter Factory to setup. + ACE_Service_Object *adapter_factory = + ACE_Dynamic_Service<TAO_Adapter_Factory>::instance ( + TAO_ORB_Core::poa_factory_name ().c_str()); - if (rt_loader != 0) - { - rt_loader->init (0, 0); - } + if (adapter_factory != 0) + { + adapter_factory->init (0, 0); + } - ACE_Service_Object *rtscheduler_loader = - ACE_Dynamic_Service<ACE_Service_Object>::instance ("RTScheduler_Loader"); + // Handle RTCORBA library special case. Since RTCORBA needs + // its init method call to register several hooks, call it + // here if it hasn't already been called. + ACE_Service_Object * const rt_loader = + ACE_Dynamic_Service<ACE_Service_Object>::instance ("RT_ORB_Loader"); - if (rtscheduler_loader != 0) - { - rtscheduler_loader->init (0, 0); - } + if (rt_loader != 0) + { + rt_loader->init (0, 0); + } - // @@ What the heck do these things do and do we need to avoid - // calling them if we're not invoking the svc.conf file? - if (TAO_Internal::resource_factory_args_ != 0) - { - ACE_Service_Config::process_directive ( - ACE_TEXT_CHAR_TO_TCHAR ( - TAO_Internal::resource_factory_args_ - ) - ); - } + ACE_Service_Object * const rtscheduler_loader = + ACE_Dynamic_Service<ACE_Service_Object>::instance ("RTScheduler_Loader"); - if (TAO_Internal::client_strategy_factory_args_ != 0) - { - ACE_Service_Config::process_directive ( - ACE_TEXT_CHAR_TO_TCHAR ( - TAO_Internal::client_strategy_factory_args_ - ) - ); - } + if (rtscheduler_loader != 0) + { + rtscheduler_loader->init (0, 0); + } - if (TAO_Internal::server_strategy_factory_args_ != 0) - { - ACE_Service_Config::process_directive ( - ACE_TEXT_CHAR_TO_TCHAR ( - TAO_Internal::server_strategy_factory_args_ - ) - ); - } + // @@ What the heck do these things do and do we need to avoid + // calling them if we're not invoking the svc.conf file? + // @@ They are needed for platforms that have no file system, + // like VxWorks. + if (resource_factory_args != 0) + { + ACE_Service_Config::process_directive ( + ACE_TEXT_CHAR_TO_TCHAR (resource_factory_args)); + } - return result; - } - else - { - return 0; - } -} + if (client_strategy_factory_args != 0) + { + ACE_Service_Config::process_directive ( + ACE_TEXT_CHAR_TO_TCHAR (client_strategy_factory_args)); + } -TAO_Internal::TAO_Internal (void) -{ -} + if (server_strategy_factory_args != 0) + { + ACE_Service_Config::process_directive ( + ACE_TEXT_CHAR_TO_TCHAR (server_strategy_factory_args)); + } -int -TAO_Internal::close_services (void) -{ - ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, - *ACE_Static_Object_Lock::instance (), -1)); - --service_open_count_; - return 0; + return result; + } + else + { + return 0; + } + } } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template class ACE_Dynamic_Service<ACE_Service_Object>; - #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#pragma instantiate ACE_Dynamic_Service<ACE_Service_Object> - +# pragma instantiate ACE_Dynamic_Service<ACE_Service_Object> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ #if defined (TAO_DEBUG) && !defined (ACE_HAS_WINCE) - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - -template class ACE_Env_Value<int>; +# if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template class ACE_Env_Value<u_int>; - -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#pragma instantiate ACE_Env_Value<int> -#pragma instantiate ACE_Env_Value<u_int> - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - -#endif /*defined TAO_DEBUG && !defined (ACE_HAS_WINCE) */ +# elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +# pragma instantiate ACE_Env_Value<u_int> +# endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ +#endif /* TAO_DEBUG && !ACE_HAS_WINCE */ diff --git a/TAO/tao/TAO_Internal.h b/TAO/tao/TAO_Internal.h index eccd7ef77ec..f814c3a8c2d 100644 --- a/TAO/tao/TAO_Internal.h +++ b/TAO/tao/TAO_Internal.h @@ -17,77 +17,52 @@ #include /**/ "ace/pre.h" -#include "TAO_Export.h" +#include "ace/config-all.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -/** - * @class TAO_Internal - * - * @brief This class encapsulates some private behaviors and global data - * structures used internal to TAO. No application should EVER - * see this class. - */ -class TAO_Export TAO_Internal -{ -public: - /// Extract ACE Service Configurator arguments from the given - /// argument vector, and initialize the ACE Service Configurator. - /// This method should be called before the ORB Core is initialized, - /// and before any ORBInitializers are invoked. - static int open_services (int &argc, ACE_TCHAR **argv); - - /** - * The complement to open_services(), this will perform appropriate - * ACE Service Configurator closure operations. It should be called - * as many times as open_services(), and will only actually close - * things down on the last call. It is fully thread-safe. Return 0 - * if successful, -1 with errno set if failure. - */ - static int close_services (void); - - /// Set default `svc.conf' content. This call has no effect if This - /// function must be called before first ORB initialization. - static void default_svc_conf_entries (const char *resource_factory_args, - const char *server_strategy_factory_args, - const char *client_strategy_factory_args); - -private: - /// Private constructor prevents this class from being - /// instantiated. - TAO_Internal (void); +namespace TAO +{ /** - * Initialize the ACE Service Configurator. This is a one-shot - * method, i.e., it can be called multiple times but it will only do - * its work once. It does, however, track the number of times it's - * called (see open_services()). It is fully thread-safe. Return 0 - * if successful, -1 with errno set if failure. You can provide - * your program a set of default `svc.conf' entries by setting - * @a ignore_default_svc_conf_file to non-zero and use - * default_svc_conf_entries() before calling open_services(). - * In addition, you can @a skip_service_config_open altogether, - * which is important if the ORB is linked in via the - * ACE_Service_Configurator, which is non-reentrant. + * @namespace ORB + * + * @brief This @c namespace encapsulates some private behaviors and + * global data structures used internal to TAO. No + * application should EVER see them which is why they are not + * exported. */ - static int open_services_i (int &argc, - char **argv, - int ignore_default_svc_conf_file = 0, - int skip_service_config_open = 0); + namespace ORB + { + /// Extract ACE Service Configurator arguments from the given + /// argument vector, and initialize the ACE Service Configurator. + /** + * @note This method should be called before the ORB Core is + * initialized, and before any ORBInitializers are invoked. + */ + int open_services (int& argc, ACE_TCHAR** argv); -private: - /// Number of times open_services() has been called. Incremented by - /// open_services(), and decremented by close_services(). Access to - /// this is protected via the \param ACE_Static_Object_Lock. - static int service_open_count_; + /** + * The complement to @c open_services(), this will perform + * appropriate ACE Service Configurator closure operations. It + * should be called as many times as @c open_services(), and will + * only actually close things down on the last call. It is fully + * thread-safe. + * @return @c 0 if successful, @c -1 with @c errno set if + * failure. + */ + int close_services (void); + /// Set default @c `svc.conf' content. This call has no effect if + /// This function must be called before first ORB initialization. + void default_svc_conf_entries (char const * rf_args, + char const * ssf_args, + char const * csf_args); - static const char *resource_factory_args_; - static const char *server_strategy_factory_args_; - static const char *client_strategy_factory_args_; -}; + } +} #include /**/ "ace/post.h" |