00001 #include "tao/Cleanup_Func_Registry.h" 00002 00003 #if !defined (__ACE_INLINE__) 00004 # include "tao/Cleanup_Func_Registry.inl" 00005 #endif /* __ACE_INLINE__ */ 00006 00007 #include "ace/Log_Msg.h" 00008 00009 ACE_RCSID (tao, 00010 Cleanup_Func_Registry, 00011 "Cleanup_Func_Registry.cpp,v 1.9 2006/03/10 07:19:04 jtc Exp") 00012 00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00014 00015 int 00016 TAO_Cleanup_Func_Registry::register_cleanup_function ( 00017 ACE_CLEANUP_FUNC func, 00018 size_t &slot_id) 00019 { 00020 size_t const slot = this->cleanup_funcs_.size (); 00021 00022 if (this->cleanup_funcs_.size (slot + 1) != 0) 00023 return -1; 00024 00025 this->cleanup_funcs_[slot] = func; 00026 slot_id = slot; 00027 00028 return 0; 00029 } 00030 00031 void 00032 TAO_Cleanup_Func_Registry::cleanup (ACE_Array_Base<void *> &ts_objects) 00033 { 00034 size_t const len = ts_objects.size (); 00035 00036 // The allocated slot may never have been used. It is therefore 00037 // possible that the TSS array size may be less than the cleanup 00038 // function size. However, there is still a one-to-one 00039 // correspondence between cleanup_func[foo] and ts_object[foo]. 00040 00041 ACE_ASSERT (len <= this->cleanup_funcs_.size ()); 00042 00043 /// Cleanup each TSS object. 00044 for (size_t i = 0; i < len; ++i) 00045 { 00046 ACE_CLEANUP_FUNC destructor = this->cleanup_funcs_[i]; 00047 if (destructor != 0) 00048 destructor (ts_objects[i], 0); 00049 } 00050 } 00051 00052 TAO_END_VERSIONED_NAMESPACE_DECL