diff options
-rw-r--r-- | TAO/tao/params.cpp | 3 | ||||
-rw-r--r-- | TAO/tao/params.h | 24 | ||||
-rw-r--r-- | TAO/tao/params.i | 72 |
3 files changed, 92 insertions, 7 deletions
diff --git a/TAO/tao/params.cpp b/TAO/tao/params.cpp index 98c59c5fdba..acfc15ad309 100644 --- a/TAO/tao/params.cpp +++ b/TAO/tao/params.cpp @@ -6,6 +6,3 @@ # include "params.i" #endif -#if defined(ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Singleton<TAO_OA_Parameters, ACE_SYNCH_MUTEX>; -#endif diff --git a/TAO/tao/params.h b/TAO/tao/params.h index 26e43c51680..f91b95ae07c 100644 --- a/TAO/tao/params.h +++ b/TAO/tao/params.h @@ -51,6 +51,12 @@ class ACE_Svc_Export TAO_OA_Parameters // parameters. { public: + static TAO_OA_Parameters *instance (void); + // Global access point to the Singleton. + + static TAO_OA_Parameters *instance (TAO_OA_Parameters*); + // Set the Singleton instance. + enum DEMUX_STRATEGY { TAO_LINEAR, @@ -134,6 +140,21 @@ public: void tablesize (CORBA_ULong tablesize); CORBA_ULong tablesize (void); +protected: +#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) + static TAO_OA_Parameters *instance_; + // Pointer to the Singleton instance. + + static TAO_OA_Parameters ace_singleton_lock_; + // Lock the creation of the singleton. +#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ + + static TAO_OA_Parameters *&instance_i (void); + // Get pointer to the Singleton instance + + static ACE_SYNCH_MUTEX &singleton_lock_i (void); + // Get reference to Singleton lock; + private: int using_threads_; @@ -163,8 +184,7 @@ private: }; // Create a type for the singleton -typedef ACE_Singleton<TAO_OA_Parameters, ACE_SYNCH_MUTEX> - TAO_OA_PARAMS; +typedef TAO_OA_Parameters TAO_OA_PARAMS; # if defined(__ACE_INLINE__) # include "params.i" diff --git a/TAO/tao/params.i b/TAO/tao/params.i index d5bd8f53f31..194490b38aa 100644 --- a/TAO/tao/params.i +++ b/TAO/tao/params.i @@ -99,8 +99,8 @@ TAO_OA_Parameters::demux_strategy (DEMUX_STRATEGY strategy) this->demux_ = strategy; // Trust that the value is valid! } -ACE_INLINE -void TAO_OA_Parameters::demux_strategy (const char* strategy) +ACE_INLINE void +TAO_OA_Parameters::demux_strategy (const char* strategy) { // Determine the demux strategy based on the given name if (!ACE_OS::strcmp (strategy, "linear")) @@ -144,4 +144,72 @@ TAO_OA_Parameters::tablesize (void) return this->tablesize_; } +ACE_INLINE TAO_OA_Parameters *& +TAO_OA_Parameters::instance_i (void) +{ +#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) + // Pointer to the Singleton instance. This works around a bug with + // G++... + static TAO_OA_Parameters *instance_ = 0; + + return instance_; +#else + return TAO_OA_Parameters::instance_; +#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ +} + +ACE_INLINE ACE_SYNCH_MUTEX & +TAO_OA_Parameters::singleton_lock_i (void) +{ +#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) + // ACE_SYNCH_MUTEX the creation of the singleton. This works around a + // "feature" of G++... ;-) + static ACE_SYNCH_MUTEX ace_singleton_lock_; + + return ace_singleton_lock_; +#else + return TAO_OA_Parameters::ace_singleton_lock_; +#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ +} + +ACE_INLINE TAO_OA_Parameters * +TAO_OA_Parameters::instance (void) +{ + ACE_TRACE ("TAO_OA_Parameters::instance"); + + TAO_OA_Parameters *&singleton = TAO_OA_Parameters::instance_i (); + + // Perform the Double-Check pattern... + if (singleton == 0) + { + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, (TAO_OA_Parameters::singleton_lock_i ()), 0); + + if (singleton == 0) + ACE_NEW_RETURN (singleton, TAO_OA_Parameters, 0); + } + + return singleton; +} + +ACE_INLINE TAO_OA_Parameters * +TAO_OA_Parameters::instance (TAO_OA_Parameters *new_instance) +{ + ACE_TRACE ("TAO_OA_Parameters::set_instance"); + + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, (TAO_OA_Parameters::singleton_lock_i ()), 0); + + TAO_OA_Parameters *&singleton = TAO_OA_Parameters::instance_i (); + TAO_OA_Parameters *old_instance = singleton; + singleton = new_instance; + + return old_instance; +} + + +#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) +// Pointer to the Singleton instance. +TAO_OA_Parameters *TAO_OA_Parameters::instance_ = 0; +// Lock the creation of the singleton. +ACE_SYNCH_MUTEX TAO_OA_Parameters::ace_singleton_lock_; +#endif /* !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */ |