From 2bfec8ecee12d87a11f16f9ea9732e722eca9f68 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 26 Jul 2018 11:54:38 +0200 Subject: [PATCH] use unique_ptrs for QueryRegistry --- arangod/Aql/QueryRegistry.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/arangod/Aql/QueryRegistry.cpp b/arangod/Aql/QueryRegistry.cpp index b217fbe8de..c94b065991 100644 --- a/arangod/Aql/QueryRegistry.cpp +++ b/arangod/Aql/QueryRegistry.cpp @@ -82,7 +82,7 @@ void QueryRegistry::insert(QueryId id, Query* query, double ttl, bool isPrepared auto m = _queries.find(vocbase.name()); if (m == _queries.end()) { m = _queries.emplace(vocbase.name(), - std::unordered_map()).first; + std::unordered_map>()).first; TRI_ASSERT(_queries.find(vocbase.name()) != _queries.end()); } @@ -94,8 +94,7 @@ void QueryRegistry::insert(QueryId id, Query* query, double ttl, bool isPrepared TRI_ERROR_INTERNAL, "query with given vocbase and id already there"); } - m->second.emplace(id, p.get()); - p.release(); + m->second.emplace(id, std::move(p)); } } @@ -117,7 +116,7 @@ Query* QueryRegistry::open(TRI_vocbase_t* vocbase, QueryId id) { return nullptr; } - QueryInfo* qi = q->second; + std::unique_ptr& qi = q->second; if (qi->_isOpen) { LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "Query with id " << id << " is already in open"; THROW_ARANGO_EXCEPTION_MESSAGE( @@ -151,7 +150,7 @@ void QueryRegistry::close(TRI_vocbase_t* vocbase, QueryId id, double ttl) { THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "query with given vocbase and id not found"); } - QueryInfo* qi = q->second; + std::unique_ptr& qi = q->second; if (!qi->_isOpen) { LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "query id " << id << " was not open."; THROW_ARANGO_EXCEPTION_MESSAGE( @@ -198,10 +197,9 @@ void QueryRegistry::destroy(std::string const& vocbase, QueryId id, // move query into our unique ptr, so we can process it outside // of the lock - queryInfo.reset(q->second); + queryInfo = std::move(q->second); // remove query from the table of running queries - q->second = nullptr; m->second.erase(q); } @@ -239,11 +237,11 @@ void QueryRegistry::expireQueries() { WRITE_LOCKER(writeLocker, _lock); for (auto& x : _queries) { // x.first is a TRI_vocbase_t* and - // x.second is a std::unordered_map + // x.second is a std::unordered_map> for (auto& y : x.second) { // y.first is a QueryId and - // y.second is a QueryInfo* - QueryInfo*& qi = y.second; + // y.second is an std::unique_ptr + std::unique_ptr const& qi = y.second; if (!qi->_isOpen && now > qi->_expires) { toDelete.emplace_back(x.first, y.first); } else {