summaryrefslogtreecommitdiff
path: root/TAO/tao/Cleanup_Func_Registry.cpp
blob: d4bb023988e08d96ce8342cb42d62e1b5b2f9bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// -*- C++ -*-
//
// $Id$

#include "Cleanup_Func_Registry.h"

#if !defined (__ACE_INLINE__)
# include "Cleanup_Func_Registry.inl"
#endif /* __ACE_INLINE__ */

ACE_RCSID (tao, Cleanup_Func_Registry, "$Id$")

TAO_Cleanup_Func_Registry::TAO_Cleanup_Func_Registry (void)
  : cleanup_funcs_ ()
{
}

TAO_Cleanup_Func_Registry::~TAO_Cleanup_Func_Registry (void)
{
}

int
TAO_Cleanup_Func_Registry::register_cleanup_function (
  ACE_CLEANUP_FUNC func,
  size_t &slot_id)
{
  size_t slot = this->cleanup_funcs_.size ();

  if (this->cleanup_funcs_.size (slot + 1) != 0)
    return -1;

  this->cleanup_funcs_[slot] = func;
  slot_id = slot;

  return 0;
}

void
TAO_Cleanup_Func_Registry::cleanup (ACE_Array_Base<void *> &ts_objects)
{
  size_t len = ts_objects.size ();

  // The allocated slot may never have been used.  It is therefore
  // possible that the TSS array size may be less than the cleanup
  // function size.  However, there is still a one-to-one
  // correspondence between cleanup_func[foo] and ts_object[foo].

  ACE_ASSERT (len <= this->cleanup_funcs_.size ());

  /// Cleanup each TSS object.
  for (size_t i = 0; i < len; ++i)
    {
      ACE_CLEANUP_FUNC destructor = this->cleanup_funcs_[i];
      if (destructor != 0)
        destructor (ts_objects[i], 0);
    }
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

template class ACE_Array_Base<ACE_CLEANUP_FUNC>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#pragma instantiate ACE_Array_Base<ACE_CLEANUP_FUNC>

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */