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
18 ACE_Cleanup::cleanup (void *)
23 ACE_Cleanup::~ACE_Cleanup ()
27 /*****************************************************************************/
30 ACE_CLEANUP_DESTROYER_NAME (ACE_Cleanup
*object
, void *param
)
32 object
->cleanup (param
);
35 /*****************************************************************************/
37 ACE_Cleanup_Info_Node::ACE_Cleanup_Info_Node ()
45 ACE_Cleanup_Info_Node::ACE_Cleanup_Info_Node (void *object
,
46 ACE_CLEANUP_FUNC cleanup_hook
,
50 cleanup_hook_ (cleanup_hook
),
52 name_ (name
? ACE_OS::strdup (name
) : 0)
56 ACE_Cleanup_Info_Node::~ACE_Cleanup_Info_Node ()
59 #if defined (ACE_HAS_ALLOC_HOOKS)
60 ACE_Allocator::instance()->free ((void *) name_
);
62 ACE_OS::free ((void *) name_
);
63 #endif /* ACE_HAS_ALLOC_HOOKS */
66 ACE_ALLOC_HOOK_DEFINE(ACE_Cleanup_Info_Node
)
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_
;
77 ACE_Cleanup_Info_Node::operator!= (const ACE_Cleanup_Info_Node
&o
) const
83 /*****************************************************************************/
85 ACE_OS_Exit_Info::ACE_OS_Exit_Info ()
89 ACE_OS_Exit_Info::~ACE_OS_Exit_Info ()
94 ACE_OS_Exit_Info::at_exit_i (void *object
,
95 ACE_CLEANUP_FUNC cleanup_hook
,
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
),
107 registered_objects_
.push_front (new_node
);
113 ACE_OS_Exit_Info::find (void *object
)
115 for (ACE_Cleanup_Info_Node
*iter
= registered_objects_
.head ();
117 iter
= iter
->next ())
119 if (iter
->object () == object
)
121 // The object has already been registered.
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 ();
135 iter
= iter
->next ())
137 if (iter
->object () == object
)
146 registered_objects_
.remove (node
);
156 ACE_OS_Exit_Info::call_hooks ()
158 // Call all registered cleanup hooks, in reverse order of
160 for (ACE_Cleanup_Info_Node
*iter
= registered_objects_
.pop_front ();
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 ()),
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 ())) ();
179 (*iter
->cleanup_hook ()) (iter
->object (), iter
->param ());
185 ACE_END_VERSIONED_NAMESPACE_DECL