diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2019-06-09 10:32:30 +0200 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2019-06-09 10:32:30 +0200 |
commit | 751c09cc92e6e90ebe476b17711f3a2ea3cc1fda (patch) | |
tree | 3f02232436c8b456389228731e865e7be550b30c | |
parent | 9953cd68ac6941641dc96b870ae4d4bf24b14c3c (diff) | |
download | ATCD-751c09cc92e6e90ebe476b17711f3a2ea3cc1fda.tar.gz |
Change the refcount_ of LiveListener to a atomic which is more efficient
* TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp:
* TAO/orbsvcs/ImplRepo_Service/LiveCheck.h:
-rw-r--r-- | TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp | 26 | ||||
-rw-r--r-- | TAO/orbsvcs/ImplRepo_Service/LiveCheck.h | 14 |
2 files changed, 21 insertions, 19 deletions
diff --git a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp index 11c494c68ff..88bb8a95e1c 100644 --- a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp +++ b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.cpp @@ -12,8 +12,7 @@ LiveListener::LiveListener (const char *server) : server_ (server), - refcount_ (1), - lock_ () + refcount_ (1) { } @@ -30,13 +29,12 @@ LiveListener::server (void) const LiveListener * LiveListener::_add_ref (void) { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, mon, this->lock_, 0); - ++this->refcount_; + int const refcount = ++this->refcount_; if (ImR_Locator_i::debug () > 5) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) LiveListener::add_ref <%C> count <%d>\n"), - server_.c_str(), refcount_)); + server_.c_str(), refcount)); } return this; } @@ -44,17 +42,13 @@ LiveListener::_add_ref (void) void LiveListener::_remove_ref (void) { - int count = 0; - { - ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_); - count = --this->refcount_; - if (ImR_Locator_i::debug () > 5) - { - ORBSVCS_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) LiveListener::remove_ref <%C> count <%d>\n"), - server_.c_str(), count)); - } - } + int const count = --this->refcount_; + if (ImR_Locator_i::debug () > 5) + { + ORBSVCS_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) LiveListener::remove_ref <%C> count <%d>\n"), + server_.c_str(), count)); + } if (count == 0) { delete this; diff --git a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h index fa9daf3c5ce..4210c97ee44 100644 --- a/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h +++ b/TAO/orbsvcs/ImplRepo_Service/LiveCheck.h @@ -22,6 +22,11 @@ #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "tao/Intrusive_Ref_Count_Handle_T.h" +#if defined (ACE_HAS_CPP11) +# include <atomic> +#else +# include "ace/Atomic_Op.h" +#endif /* ACE_HAS_CPP11 */ class LiveCheck; class LiveEntry; @@ -81,7 +86,7 @@ class Locator_Export LiveListener /// is received. Returns true if finished listening virtual bool status_changed (LiveStatus status) = 0; - /// accessor for the server name. Used by the LiveCheck to associate a listener + /// Accessor for the server name. Used by the LiveCheck to associate a listener const char *server (void) const; LiveListener *_add_ref (void); @@ -91,8 +96,11 @@ class Locator_Export LiveListener ACE_CString server_; private: - int refcount_; - TAO_SYNCH_MUTEX lock_; +#if defined (ACE_HAS_CPP11) + std::atomic<int> refcount_; +#else + ACE_Atomic_Op<TAO_SYNCH_MUTEX, int> refcount_; +#endif /* ACE_HAS_CPP11 */ }; typedef TAO_Intrusive_Ref_Count_Handle<LiveListener> LiveListener_ptr; |