summaryrefslogtreecommitdiff
path: root/ace/Object_Manager.cpp
blob: 0f31c3daa697df1d9eff512b30788c6a2e428294 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// $Id$

#define ACE_BUILD_DLL

#include "ace/Object_Manager.h"
#include "ace/Service_Repository.h"

#if !defined (__ACE_INLINE__)
#include "ace/Object_Manager.i"
#endif /* __ACE_INLINE__ */

ACE_Object_Manager *ACE_Object_Manager::instance_ = 0;

ACE_Object_Manager::ACE_Object_Manager (void)
{
}

ACE_Object_Manager::~ACE_Object_Manager (void)
{
  void *p;
  int i;

  // Delete all registered objects and arrays.
  while ((i = registered_objects_.dequeue_head (p)) != -1)
    delete p;

  while ((i = registered_arrays_.dequeue_head (p)) != -1)
    delete [] p;

  // This call closes and deletes all ACE library services and
  // singletons.
  ACE_Service_Config::close ();
}

ACE_Object_Manager *
ACE_Object_Manager::instance (void)
{
  // This function should be call during construction of static
  // instances, so it's not thread safe.

  if (instance_ == 0)
    ACE_NEW_RETURN (instance_, ACE_Object_Manager, 0);

  return instance_;
}

int
ACE_Object_Manager::delete_at_exit_i (void *object)
{
  // Check for already in queue, and return 1 if so.
  ACE_Unbounded_Queue_Iterator<void *> i (registered_objects_);
  void **obj;

  while (i.next (obj))
    {
      i.advance ();

      if (obj == object)
	// The object has already been registered.
	return 1;
    }

  // Returns -1 if unable to allocate storage.
  return registered_objects_.enqueue_tail (object);
}

int
ACE_Object_Manager::delete_array_at_exit_i (void *array)
{
  // Check for already in queue, and return 1 if so.
  ACE_Unbounded_Queue_Iterator<void *> i (registered_arrays_);
  void **obj;

  while (i.next (obj))
    {
      i.advance ();

      if (obj == array)
	// The array has already been registered.
	return 1;
    }

  // Returns -1 if unable to allocate storage.
  return registered_arrays_.enqueue_tail (array);
}

#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION)
template class ACE_Unbounded_Queue<void *>;
template class ACE_Unbounded_Queue_Iterator<void *>;
template class ACE_Node<void *>;
#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */