diff options
-rw-r--r-- | ace/Object_Manager.cpp | 26 | ||||
-rw-r--r-- | ace/Object_Manager.h | 33 | ||||
-rw-r--r-- | tests/Service_Config_Test.cpp | 56 |
3 files changed, 57 insertions, 58 deletions
diff --git a/ace/Object_Manager.cpp b/ace/Object_Manager.cpp index b0b0cd21de3..1d396c838c1 100644 --- a/ace/Object_Manager.cpp +++ b/ace/Object_Manager.cpp @@ -22,12 +22,10 @@ ACE_Object_Manager::~ACE_Object_Manager (void) { object_info_t info; - // Call all registered cleanup hooks, in reverse order - // of registration. + // Call all registered cleanup hooks, in reverse order of + // registration. while (registered_objects_.dequeue_head (info) != -1) - { - (*info.cleanup_hook_) (info.object_, info.param_); - } + (*info.cleanup_hook_) (info.object_, info.param_); // This call closes and deletes all ACE library services and // singletons. @@ -54,26 +52,24 @@ ACE_Object_Manager::at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) { - // Check for already in queue, and return 1 if so. object_info_t *info = 0; + + // Check for already in queue, and return 1 if so. + for (ACE_Unbounded_Queue_Iterator<object_info_t> iter (registered_objects_); iter.next (info) != 0; iter.advance ()) - { - if (info->object_ == object) - { - // The object has already been registered. - return 1; - } - } + if (info->object_ == object) + // The object has already been registered. + return 1; object_info_t new_info; new_info.object_ = object; new_info.cleanup_hook_ = cleanup_hook; new_info.param_ = param; - // Returns -1 if unable to allocate storage. - // Enqueue at the head and dequeue from the head to get LIFO ordering. + // Returns -1 if unable to allocate storage. Enqueue at the head + // and dequeue from the head to get LIFO ordering. return registered_objects_.enqueue_head (new_info); } diff --git a/ace/Object_Manager.h b/ace/Object_Manager.h index bd2610d9d15..8f3da2abcbd 100644 --- a/ace/Object_Manager.h +++ b/ace/Object_Manager.h @@ -51,16 +51,16 @@ public: ACE_CLEANUP_FUNC cleanup_hook, void *param); // Register an object (or array) for cleanup at process termination. - // "cleanup_hook" points to a (global, or static member) function that - // is called for the object or array when it to be destroyed. It may - // perform any necessary cleanup specific for that object or its class. - // "param" is passed as the second parameter to the "cleanup_hook" - // function; the first parameter is the object (or array) to be destroyed. - // "cleanup_hook", for example, may delete the object (or array). - // For OS's that do not have processes, this function is the same - // as at_thread_exit (). - // Returns 0 on success, non-zero on failure: -1 if virtual memory is - // exhausted or 1 if the object (or arrayt) had already been registered. + // "cleanup_hook" points to a (global, or static member) function + // that is called for the object or array when it to be destroyed. + // It may perform any necessary cleanup specific for that object or + // its class. "param" is passed as the second parameter to the + // "cleanup_hook" function; the first parameter is the object (or + // array) to be destroyed. "cleanup_hook", for example, may delete + // the object (or array). For OS's that do not have processes, this + // function is the same as at_thread_exit (). Returns 0 on success, + // non-zero on failure: -1 if virtual memory is exhausted or 1 if + // the object (or arrayt) had already been registered. #if 0 /* not implemented yet */ static int at_thread_exit (void *object, @@ -71,20 +71,22 @@ public: #endif /* 0 */ private: - // not currently used: // typedef void (*ACE_CONSTRUCT_FUNC)(void *object, void *param); + // not currently used: static ACE_Object_Manager *instance_; // Singleton pointer. -public: // For template instantiation, with some compilers that need the - // struct definition to be public. +public: + // For template instantiation, with some compilers that need the + // struct definition to be public. typedef struct object_info { void *object_; ACE_CLEANUP_FUNC cleanup_hook_; void *param_; } object_info_t; + private: ACE_Unbounded_Queue<object_info_t> registered_objects_; @@ -94,12 +96,13 @@ private: // Register an object or array for deletion at program termination. // See description of static version above for return values. + // = Make these private to prevent explicit instantiation. ACE_Object_Manager (void); ~ACE_Object_Manager (void); static ACE_Object_Manager *instance (void); - // Accessor to singleton instance. Because static member functions are - // provided in the interface, this does not need to be public. + // Accessor to singleton instance. Because static member functions + // are provided in the interface, this does not need to be public. friend class ACE_Object_Manager_Destroyer; diff --git a/tests/Service_Config_Test.cpp b/tests/Service_Config_Test.cpp index 04019f529b6..b805390ae3c 100644 --- a/tests/Service_Config_Test.cpp +++ b/tests/Service_Config_Test.cpp @@ -13,7 +13,7 @@ // working correctly. // // = AUTHOR -// Doug Schmidt +// David Levine // // ============================================================================ @@ -22,31 +22,31 @@ #include "test_config.h" template <int NUMBER> -class mySingleton +class Test_Singleton { public: - static mySingleton *instance (); + static Test_Singleton *instance (void); static void cleanup (void *, void *); private: - static mySingleton *instance_; + static Test_Singleton *instance_; - mySingleton () { ACE_DEBUG ((LM_DEBUG, "mySingleton %d ctor\n", NUMBER)); } - ~mySingleton () { ACE_DEBUG ((LM_DEBUG, "mySingleton %d dtor\n", NUMBER)); } + Test_Singleton (void) { ACE_DEBUG ((LM_DEBUG, "Test_Singleton %d ctor\n", NUMBER)); } + ~Test_Singleton (void) { ACE_DEBUG ((LM_DEBUG, "Test_Singleton %d dtor\n", NUMBER)); } - friend class friend_declaration_to_avoid_compiler_warning_with_private_ctor; + friend class verbase_friend_declaration_to_avoid_compiler_warning_with_private_ctor; }; -mySingleton<1> *mySingleton<1>::instance_ = 0; -mySingleton<2> *mySingleton<2>::instance_ = 0; -mySingleton<3> *mySingleton<3>::instance_ = 0; +Test_Singleton<1> *Test_Singleton<1>::instance_ = 0; +Test_Singleton<2> *Test_Singleton<2>::instance_ = 0; +Test_Singleton<3> *Test_Singleton<3>::instance_ = 0; template <int NUMBER> -mySingleton<NUMBER> * -mySingleton<NUMBER>::instance () +Test_Singleton<NUMBER> * +Test_Singleton<NUMBER>::instance (void) { if (instance_ == 0) { - ACE_NEW_RETURN (instance_, mySingleton, 0); + ACE_NEW_RETURN (instance_, Test_Singleton, 0); ACE_Object_Manager::at_exit (instance_, cleanup, 0); } @@ -55,15 +55,16 @@ mySingleton<NUMBER>::instance () template <int NUMBER> void -mySingleton<NUMBER>::cleanup (void *object, void *) +Test_Singleton<NUMBER>::cleanup (void *object, void *) { - delete (mySingleton *) object; + delete (Test_Singleton *) object; } static void run_test (int argc, char *argv[]) { - // We need this scope to make sure + // We need this scope to make sure that the destructor for the + // ACE_Service_Config gets called. ACE_Service_Config daemon; daemon.open (argc, argv); @@ -78,13 +79,12 @@ main (int argc, char *argv[]) { ACE_START_TEST ("Service_Config_Test"); - mySingleton<1> &one = *mySingleton<1>::instance (); - mySingleton<2> &two = *mySingleton<2>::instance (); - mySingleton<3> &three = *mySingleton<3>::instance (); + Test_Singleton<1> &one = *Test_Singleton<1>::instance (); + Test_Singleton<2> &two = *Test_Singleton<2>::instance (); + Test_Singleton<3> &three = *Test_Singleton<3>::instance (); + if (&one == 0 || &two == 0 || &three == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, "instance () allocate failed!\n"), 1); - } + ACE_ERROR_RETURN ((LM_ERROR, "instance () allocate failed!\n"), 1); run_test (argc, argv); @@ -93,12 +93,12 @@ main (int argc, char *argv[]) } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class mySingleton<1>; -template class mySingleton<2>; -template class mySingleton<3>; +template class Test_Singleton<1>; +template class Test_Singleton<2>; +template class Test_Singleton<3>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate mySingleton<1> -#pragma instantiate mySingleton<2> -#pragma instantiate mySingleton<3> +#pragma instantiate Test_Singleton<1> +#pragma instantiate Test_Singleton<2> +#pragma instantiate Test_Singleton<3> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ |