From 92a6531e409f2691d82591e185a92299d415fc0f Mon Sep 17 00:00:00 2001 From: Joe George Date: Thu, 28 Jan 2021 16:26:44 -0500 Subject: IceGrid and IceStorm --- cpp/src/IceGrid/ObjectCache.cpp | 70 +++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 42 deletions(-) (limited to 'cpp/src/IceGrid/ObjectCache.cpp') diff --git a/cpp/src/IceGrid/ObjectCache.cpp b/cpp/src/IceGrid/ObjectCache.cpp index caa5a75d3db..3ea4e33495d 100644 --- a/cpp/src/IceGrid/ObjectCache.cpp +++ b/cpp/src/IceGrid/ObjectCache.cpp @@ -14,57 +14,43 @@ using namespace std; using namespace IceGrid; -pointer_to_unary_function ObjectCache::_rand(IceUtilInternal::random); - namespace IceGrid { -struct ObjectEntryCI : binary_function +bool compareObjectEntryCI(const shared_ptr& lhs, const shared_ptr& rhs) { + return Ice::proxyIdentityLess(lhs->getProxy(), rhs->getProxy()); +} - bool - operator()(const ObjectEntryPtr& lhs, const ObjectEntryPtr& rhs) - { - return ::Ice::proxyIdentityLess(lhs->getProxy(), rhs->getProxy()); - } -}; - -struct ObjectLoadCI : binary_function&, pair&, bool> +bool compareObjectLoadCI(const pair& lhs, const pair& rhs) { - bool operator()(const pair& lhs, const pair& rhs) - { - return lhs.second < rhs.second; - } -}; + return lhs.second < rhs.second; +} }; -ObjectCache::TypeEntry::TypeEntry() -{ -} - void -ObjectCache::TypeEntry::add(const ObjectEntryPtr& obj) +ObjectCache::TypeEntry::add(const shared_ptr& obj) { // // No mutex protection here, this is called with the cache locked. // - _objects.insert(lower_bound(_objects.begin(), _objects.end(), obj, ObjectEntryCI()), obj); + _objects.insert(lower_bound(_objects.begin(), _objects.end(), obj, compareObjectEntryCI), obj); } bool -ObjectCache::TypeEntry::remove(const ObjectEntryPtr& obj) +ObjectCache::TypeEntry::remove(const shared_ptr& obj) { // // No mutex protection here, this is called with the cache locked. // - vector::iterator q = lower_bound(_objects.begin(), _objects.end(), obj, ObjectEntryCI()); + auto q = lower_bound(_objects.begin(), _objects.end(), obj, compareObjectEntryCI); assert(q->get() == obj.get()); _objects.erase(q); return _objects.empty(); } -ObjectCache::ObjectCache(const Ice::CommunicatorPtr& communicator) : _communicator(communicator) +ObjectCache::ObjectCache(const shared_ptr& communicator) : _communicator(communicator) { } @@ -73,7 +59,7 @@ ObjectCache::add(const ObjectInfo& info, const string& application, const string { const Ice::Identity& id = info.proxy->ice_getIdentity(); - Lock sync(*this); + lock_guard lock(_mutex); if(getImpl(id)) { Ice::Error out(_communicator->getLogger()); @@ -81,13 +67,13 @@ ObjectCache::add(const ObjectInfo& info, const string& application, const string return; } - ObjectEntryPtr entry = new ObjectEntry(info, application, server); + auto entry = make_shared(info, application, server); addImpl(id, entry); map::iterator p = _types.find(entry->getType()); if(p == _types.end()) { - p = _types.insert(p, map::value_type(entry->getType(), TypeEntry())); + p = _types.insert(p, { entry->getType(), TypeEntry() }); } p->second.add(entry); @@ -98,11 +84,11 @@ ObjectCache::add(const ObjectInfo& info, const string& application, const string } } -ObjectEntryPtr +shared_ptr ObjectCache::get(const Ice::Identity& id) const { - Lock sync(*this); - ObjectEntryPtr entry = getImpl(id); + lock_guard lock(_mutex); + shared_ptr entry = getImpl(id); if(!entry) { throw ObjectNotRegisteredException(id); @@ -113,8 +99,8 @@ ObjectCache::get(const Ice::Identity& id) const void ObjectCache::remove(const Ice::Identity& id) { - Lock sync(*this); - ObjectEntryPtr entry = getImpl(id); + lock_guard lock(_mutex); + shared_ptr entry = getImpl(id); if(!entry) { Ice::Error out(_communicator->getLogger()); @@ -137,14 +123,14 @@ ObjectCache::remove(const Ice::Identity& id) } } -vector +vector> ObjectCache::getObjectsByType(const string& type) { - Lock sync(*this); + lock_guard lock(_mutex); map::const_iterator p = _types.find(type); if(p == _types.end()) { - return vector(); + return vector>(); } return p->second.getObjects(); } @@ -152,9 +138,9 @@ ObjectCache::getObjectsByType(const string& type) ObjectInfoSeq ObjectCache::getAll(const string& expression) { - Lock sync(*this); + lock_guard lock(_mutex); ObjectInfoSeq infos; - for(map::const_iterator p = _entries.begin(); p != _entries.end(); ++p) + for(auto p = _entries.cbegin(); p != _entries.cend(); ++p) { if(expression.empty() || IceUtilInternal::match(_communicator->identityToString(p->first), expression, true)) { @@ -167,7 +153,7 @@ ObjectCache::getAll(const string& expression) ObjectInfoSeq ObjectCache::getAllByType(const string& type) { - Lock sync(*this); + lock_guard lock(_mutex); ObjectInfoSeq infos; map::const_iterator p = _types.find(type); if(p == _types.end()) @@ -175,8 +161,8 @@ ObjectCache::getAllByType(const string& type) return infos; } - const vector& objects = p->second.getObjects(); - for(vector::const_iterator q = objects.begin(); q != objects.end(); ++q) + const vector>& objects = p->second.getObjects(); + for(vector>::const_iterator q = objects.begin(); q != objects.end(); ++q) { infos.push_back((*q)->getObjectInfo()); } @@ -190,7 +176,7 @@ ObjectEntry::ObjectEntry(const ObjectInfo& info, const string& application, cons { } -Ice::ObjectPrx +shared_ptr ObjectEntry::getProxy() const { return _info.proxy; -- cgit v1.2.3