Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / Cleanup.cpp
blob46b3c7e75826bef7575e5668276e119f3341bf03
1 #include "ace/Cleanup.h"
3 #if !defined (ACE_HAS_INLINED_OSCALLS)
4 # include "ace/Cleanup.inl"
5 #endif /* ACE_HAS_INLINED_OSCALLS */
7 #include "ace/OS_Memory.h"
8 #include "ace/OS_NS_string.h"
9 #include "ace/os_include/os_typeinfo.h"
11 #if defined (ACE_HAS_ALLOC_HOOKS)
12 # include "ace/Malloc_Base.h"
13 #endif /* ACE_HAS_ALLOC_HOOKS */
15 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 void
18 ACE_Cleanup::cleanup (void *)
20 delete this;
23 ACE_Cleanup::~ACE_Cleanup ()
27 /*****************************************************************************/
29 extern "C" void
30 ACE_CLEANUP_DESTROYER_NAME (ACE_Cleanup *object, void *param)
32 object->cleanup (param);
35 /*****************************************************************************/
37 ACE_Cleanup_Info_Node::ACE_Cleanup_Info_Node ()
38 : object_ (0),
39 cleanup_hook_ (0),
40 param_ (0),
41 name_ (0)
45 ACE_Cleanup_Info_Node::ACE_Cleanup_Info_Node (void *object,
46 ACE_CLEANUP_FUNC cleanup_hook,
47 void *param,
48 const char *name)
49 : object_ (object),
50 cleanup_hook_ (cleanup_hook),
51 param_ (param),
52 name_ (name ? ACE_OS::strdup (name) : 0)
56 ACE_Cleanup_Info_Node::~ACE_Cleanup_Info_Node ()
58 if (this->name_)
59 #if defined (ACE_HAS_ALLOC_HOOKS)
60 ACE_Allocator::instance()->free ((void *) name_);
61 #else
62 ACE_OS::free ((void *) name_);
63 #endif /* ACE_HAS_ALLOC_HOOKS */
66 ACE_ALLOC_HOOK_DEFINE(ACE_Cleanup_Info_Node)
68 bool
69 ACE_Cleanup_Info_Node::operator== (const ACE_Cleanup_Info_Node &o) const
71 return o.object_ == this->object_
72 && o.cleanup_hook_ == this->cleanup_hook_
73 && o.param_ == this->param_;
76 bool
77 ACE_Cleanup_Info_Node::operator!= (const ACE_Cleanup_Info_Node &o) const
79 return !(*this == o);
83 /*****************************************************************************/
85 ACE_OS_Exit_Info::ACE_OS_Exit_Info ()
89 ACE_OS_Exit_Info::~ACE_OS_Exit_Info ()
93 int
94 ACE_OS_Exit_Info::at_exit_i (void *object,
95 ACE_CLEANUP_FUNC cleanup_hook,
96 void *param,
97 const char* name)
99 // Return -1 and sets errno if unable to allocate storage. Enqueue
100 // at the head and dequeue from the head to get LIFO ordering.
101 ACE_Cleanup_Info_Node *new_node = 0;
103 ACE_NEW_RETURN (new_node,
104 ACE_Cleanup_Info_Node (object, cleanup_hook, param, name),
105 -1);
107 registered_objects_.push_front (new_node);
109 return 0;
112 bool
113 ACE_OS_Exit_Info::find (void *object)
115 for (ACE_Cleanup_Info_Node *iter = registered_objects_.head ();
116 iter != 0;
117 iter = iter->next ())
119 if (iter->object () == object)
121 // The object has already been registered.
122 return true;
126 return false;
129 bool
130 ACE_OS_Exit_Info::remove (void *object)
132 ACE_Cleanup_Info_Node *node = 0;
133 for (ACE_Cleanup_Info_Node *iter = registered_objects_.head ();
134 iter != 0;
135 iter = iter->next ())
137 if (iter->object () == object)
139 node = iter;
140 break;
144 if (node)
146 registered_objects_.remove (node);
147 delete node;
148 return true;
151 return false;
155 void
156 ACE_OS_Exit_Info::call_hooks ()
158 // Call all registered cleanup hooks, in reverse order of
159 // registration.
160 for (ACE_Cleanup_Info_Node *iter = registered_objects_.pop_front ();
161 iter != 0;
162 iter = registered_objects_.pop_front ())
164 if (iter->cleanup_hook () == reinterpret_cast<ACE_CLEANUP_FUNC> (
165 ACE_CLEANUP_DESTROYER_NAME))
167 // The object is an ACE_Cleanup.
168 ACE_CLEANUP_DESTROYER_NAME (
169 reinterpret_cast<ACE_Cleanup *> (iter->object ()),
170 iter->param ());
172 else if (iter->object () == &ace_exit_hook_marker)
174 // The hook is an ACE_EXIT_HOOK.
175 (* reinterpret_cast<ACE_EXIT_HOOK> (iter->cleanup_hook ())) ();
177 else
179 (*iter->cleanup_hook ()) (iter->object (), iter->param ());
181 delete iter;
185 ACE_END_VERSIONED_NAMESPACE_DECL