Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Monitor_Point_Registry.cpp
blobb448ab77e89d4b6b3b45acba396f3de658c53a81
1 #include "ace/Monitor_Point_Registry.h"
3 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
5 #include "ace/Monitor_Base.h"
6 #include "ace/Guard_T.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 namespace ACE
12 namespace Monitor_Control
14 Monitor_Point_Registry*
15 Monitor_Point_Registry::instance ()
17 return
18 ACE_Singleton<Monitor_Point_Registry, ACE_SYNCH_MUTEX>::instance ();
21 bool
22 Monitor_Point_Registry::add (Monitor_Base* type)
24 if (type == 0)
26 ACELIB_ERROR_RETURN ((LM_ERROR,
27 "registry add: null type\n"),
28 false);
31 int status = 0;
34 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, false);
36 type->add_ref ();
38 status = this->map_.bind (type->name (), type);
41 if (status == -1)
43 ACELIB_ERROR_RETURN ((LM_ERROR,
44 "registry add: map bind failed\n"),
45 false);
48 return (status == 0);
51 bool
52 Monitor_Point_Registry::remove (const char* name)
54 if (name == 0)
56 ACELIB_ERROR_RETURN ((LM_ERROR,
57 "registry remove: null name\n"),
58 false);
61 int status = 0;
62 Map::data_type mp = 0;
65 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, false);
67 ACE_CString name_str (name, 0, false);
68 status = this->map_.unbind (name_str, mp);
71 if (status == -1)
73 // (JP) There is a problem with this failing on a single ACE_Message_Queue
74 // monitor per process. I think it is the message queue associated
75 // with the default reactor, maybe because at that low level, ACE
76 // is using malloc with placement, then free, which may bypass the
77 // normal destructors. In any case, it happens only at shutdown
78 // and there seems to be no memory leak.
79 // ACELIB_ERROR_RETURN ((LM_ERROR,
80 // "registry remove: unbind failed for %s\n",
81 // name),
82 // false);
84 else
86 mp->remove_ref ();
89 return (status == 0);
92 Monitor_Control_Types::NameList
93 Monitor_Point_Registry::names ()
95 Monitor_Control_Types::NameList name_holder_;
98 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
100 for (Map::CONST_ITERATOR i (this->map_); !i.done (); i.advance ())
102 name_holder_.push_back (i->key ());
106 return name_holder_;
109 Monitor_Base*
110 Monitor_Point_Registry::get (const ACE_CString& name) const
112 Map::data_type mp = 0;
115 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
117 this->map_.find (name, mp);
120 if (mp != 0)
122 mp->add_ref ();
125 return mp;
128 long
129 Monitor_Point_Registry::constraint_id ()
131 long retval = 0;
134 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, -1);
136 retval = this->constraint_id_++;
139 return retval;
142 void
143 Monitor_Point_Registry::cleanup ()
145 for (Map::ITERATOR i = this->map_.begin ();
146 i != this->map_.end ();
147 i.advance ())
149 Map::ENTRY* entry = 0;
150 i.next (entry);
151 entry->int_id_->remove_ref ();
157 ACE_END_VERSIONED_NAMESPACE_DECL
159 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */