From de5b3eb2c76dd1256f512120d1a5cfddf9f4c7fc Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 17 Dec 2019 12:13:30 +0100 Subject: [PATCH] RedisConnection: replace std::shared_ptr with Shared::Ptr --- lib/icingadb/redisconnection.cpp | 13 +++++++------ lib/icingadb/redisconnection.hpp | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/icingadb/redisconnection.cpp b/lib/icingadb/redisconnection.cpp index bd94273d9..65c270d8d 100644 --- a/lib/icingadb/redisconnection.cpp +++ b/lib/icingadb/redisconnection.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -75,7 +76,7 @@ void RedisConnection::FireAndForgetQuery(RedisConnection::Query query, RedisConn LogQuery(query, msg); } - auto item (std::make_shared(std::move(query))); + auto item (Shared::Make(std::move(query))); asio::post(m_Strand, [this, item, priority]() { m_Queues.Writes[priority].emplace(WriteQueueItem{item, nullptr, nullptr, nullptr}); @@ -90,7 +91,7 @@ void RedisConnection::FireAndForgetQueries(RedisConnection::Queries queries, Red LogQuery(query, msg); } - auto item (std::make_shared(std::move(queries))); + auto item (Shared::Make(std::move(queries))); asio::post(m_Strand, [this, item, priority]() { m_Queues.Writes[priority].emplace(WriteQueueItem{nullptr, item, nullptr, nullptr}); @@ -107,7 +108,7 @@ RedisConnection::Reply RedisConnection::GetResultOfQuery(RedisConnection::Query std::promise promise; auto future (promise.get_future()); - auto item (std::make_shared(std::move(query), std::move(promise))); + auto item (Shared>>::Make(std::move(query), std::move(promise))); asio::post(m_Strand, [this, item, priority]() { m_Queues.Writes[priority].emplace(WriteQueueItem{nullptr, nullptr, item, nullptr}); @@ -128,7 +129,7 @@ RedisConnection::Replies RedisConnection::GetResultsOfQueries(RedisConnection::Q std::promise promise; auto future (promise.get_future()); - auto item (std::make_shared(std::move(queries), std::move(promise))); + auto item (Shared>>::Make(std::move(queries), std::move(promise))); asio::post(m_Strand, [this, item, priority]() { m_Queues.Writes[priority].emplace(WriteQueueItem{nullptr, nullptr, nullptr, item}); @@ -152,14 +153,14 @@ void RedisConnection::Connect(asio::yield_context& yc) Log(LogInformation, "IcingaDB") << "Trying to connect to Redis server (async) on host '" << m_Host << ":" << m_Port << "'"; - decltype(m_TcpConn) conn (new TcpConn(m_Strand.context())); + auto conn (Shared::Make(m_Strand.context())); icinga::Connect(conn->next_layer(), m_Host, Convert::ToString(m_Port), yc); m_TcpConn = std::move(conn); } else { Log(LogInformation, "IcingaDB") << "Trying to connect to Redis server (async) on unix socket path '" << m_Path << "'"; - decltype(m_UnixConn) conn (new UnixConn(m_Strand.context())); + auto conn (Shared::Make(m_Strand.context())); conn->next_layer().async_connect(Unix::endpoint(m_Path.CStr()), yc); m_UnixConn = std::move(conn); } diff --git a/lib/icingadb/redisconnection.hpp b/lib/icingadb/redisconnection.hpp index a9767d408..5b3e8e324 100644 --- a/lib/icingadb/redisconnection.hpp +++ b/lib/icingadb/redisconnection.hpp @@ -7,6 +7,7 @@ #include "base/atomic.hpp" #include "base/io-engine.hpp" #include "base/object.hpp" +#include "base/shared.hpp" #include "base/string.hpp" #include "base/value.hpp" #include @@ -87,10 +88,10 @@ namespace icinga struct WriteQueueItem { - std::shared_ptr FireAndForgetQuery; - std::shared_ptr FireAndForgetQueries; - std::shared_ptr>> GetResultOfQuery; - std::shared_ptr>> GetResultsOfQueries; + Shared::Ptr FireAndForgetQuery; + Shared::Ptr FireAndForgetQueries; + Shared>>::Ptr GetResultOfQuery; + Shared>>::Ptr GetResultsOfQueries; }; typedef boost::asio::ip::tcp Tcp; @@ -133,8 +134,8 @@ namespace icinga int m_DbIndex; boost::asio::io_context::strand m_Strand; - std::shared_ptr m_TcpConn; - std::shared_ptr m_UnixConn; + Shared::Ptr m_TcpConn; + Shared::Ptr m_UnixConn; Atomic m_Connecting, m_Connected, m_Started; struct {