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 "$Id: Cleanup_Func_Registry.cpp 77639 2007-03-09 12:58:47Z johnnyw $") 00012 00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00014 00015 int 00016 TAO_Cleanup_Func_Registry::register_cleanup_function (ACE_CLEANUP_FUNC func, 00017 size_t &slot_id) 00018 { 00019 size_t const slot = this->cleanup_funcs_.size (); 00020 00021 if (this->cleanup_funcs_.size (slot + 1) != 0) 00022 return -1; 00023 00024 this->cleanup_funcs_[slot] = func; 00025 slot_id = slot; 00026 00027 return 0; 00028 } 00029 00030 void 00031 TAO_Cleanup_Func_Registry::cleanup (ACE_Array_Base <void *> &ts_objects) 00032 { 00033 size_t const len = ts_objects.size (); 00034 00035 // The allocated slot may never have been used. It is therefore 00036 // possible that the TSS array size may be less than the cleanup 00037 // function size. However, there is still a one-to-one 00038 // correspondence between cleanup_func[foo] and ts_object[foo]. 00039 00040 ACE_ASSERT (len <= this->cleanup_funcs_.size ()); 00041 00042 /// Cleanup each TSS object. 00043 for (size_t i = 0; i < len; ++i) 00044 { 00045 ACE_CLEANUP_FUNC destructor = this->cleanup_funcs_[i]; 00046 if (destructor != 0) 00047 destructor (ts_objects[i], 0); 00048 } 00049 } 00050 00051 TAO_END_VERSIONED_NAMESPACE_DECL