From 465945f8a8e67ad6ec50b6a38220a831e05180c5 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 16 Jun 2015 13:14:33 -0400 Subject: [PATCH] more generic queue --- NetDb.h | 2 +- Queue.h | 30 +++++++++++++++--------------- Tunnel.h | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/NetDb.h b/NetDb.h index 2c6e78be..6b96f155 100644 --- a/NetDb.h +++ b/NetDb.h @@ -89,7 +89,7 @@ namespace data bool m_IsRunning; std::thread * m_Thread; - i2p::util::Queue m_Queue; // of I2NPDatabaseStoreMsg + i2p::util::Queue m_Queue; // of I2NPDatabaseStoreMsg Reseeder * m_Reseeder; diff --git a/Queue.h b/Queue.h index 086d6d81..6f50e189 100644 --- a/Queue.h +++ b/Queue.h @@ -17,14 +17,14 @@ namespace util { public: - void Put (Element * e) + void Put (Element e) { std::unique_lock l(m_QueueMutex); m_Queue.push (e); m_NonEmpty.notify_one (); } - void Put (const std::vector& vec) + void Put (const std::vector& vec) { if (!vec.empty ()) { @@ -35,10 +35,10 @@ namespace util } } - Element * GetNext () + Element GetNext () { std::unique_lock l(m_QueueMutex); - Element * el = GetNonThreadSafe (); + auto el = GetNonThreadSafe (); if (!el) { m_NonEmpty.wait (l); @@ -47,10 +47,10 @@ namespace util return el; } - Element * GetNextWithTimeout (int usec) + Element GetNextWithTimeout (int usec) { std::unique_lock l(m_QueueMutex); - Element * el = GetNonThreadSafe (); + auto el = GetNonThreadSafe (); if (!el) { m_NonEmpty.wait_for (l, std::chrono::milliseconds (usec)); @@ -85,13 +85,13 @@ namespace util void WakeUp () { m_NonEmpty.notify_all (); }; - Element * Get () + Element Get () { std::unique_lock l(m_QueueMutex); return GetNonThreadSafe (); } - Element * Peek () + Element Peek () { std::unique_lock l(m_QueueMutex); return GetNonThreadSafe (true); @@ -99,11 +99,11 @@ namespace util private: - Element * GetNonThreadSafe (bool peek = false) + Element GetNonThreadSafe (bool peek = false) { if (!m_Queue.empty ()) { - Element * el = m_Queue.front (); + auto el = m_Queue.front (); if (!peek) m_Queue.pop (); return el; @@ -113,13 +113,13 @@ namespace util private: - std::queue m_Queue; + std::queue m_Queue; std::mutex m_QueueMutex; std::condition_variable m_NonEmpty; }; template - class MsgQueue: public Queue + class MsgQueue: public Queue { public: @@ -132,7 +132,7 @@ namespace util if (m_IsRunning) { m_IsRunning = false; - Queue::WakeUp (); + Queue::WakeUp (); m_Thread.join(); } } @@ -145,7 +145,7 @@ namespace util { while (m_IsRunning) { - while (Msg * msg = Queue::Get ()) + while (auto msg = Queue::Get ()) { msg->Process (); delete msg; @@ -153,7 +153,7 @@ namespace util if (m_OnEmpty != nullptr) m_OnEmpty (); if (m_IsRunning) - Queue::Wait (); + Queue::Wait (); } } diff --git a/Tunnel.h b/Tunnel.h index be15aa91..b6362997 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -177,7 +177,7 @@ namespace tunnel std::mutex m_PoolsMutex; std::list> m_Pools; std::shared_ptr m_ExploratoryPool; - i2p::util::Queue m_Queue; + i2p::util::Queue m_Queue; // some stats int m_NumSuccesiveTunnelCreations, m_NumFailedTunnelCreations;