From ebae3dee3e5dd6a008b2240d9248dbc6be5e744c Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 9 Jul 2020 17:39:56 +0200 Subject: [PATCH] when in shutdown exit this loop --- Adapter.cc | 9 +++++++++ Adapter.hh | 1 + callback_dispatcher.cc | 3 +++ locked_queue.hh | 8 ++++---- pc_container.hh | 4 ++-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Adapter.cc b/Adapter.cc index d108907..18b86e4 100644 --- a/Adapter.cc +++ b/Adapter.cc @@ -144,5 +144,14 @@ namespace pEp { { return _sync_thread != nullptr; } + + bool in_shutdown() + { + SYNC_EVENT ev = q.back(); + if (ev) + return false; + else + return true; + } } } diff --git a/Adapter.hh b/Adapter.hh index 41995fb..d5faac2 100644 --- a/Adapter.hh +++ b/Adapter.hh @@ -51,6 +51,7 @@ namespace pEp { void shutdown(); bool is_sync_running(); + bool in_shutdown(); } } diff --git a/callback_dispatcher.cc b/callback_dispatcher.cc index c1e8d1d..f465493 100644 --- a/callback_dispatcher.cc +++ b/callback_dispatcher.cc @@ -94,6 +94,9 @@ namespace pEp { if (Adapter::on_sync_thread() && !msg) { semaphore.try_wait(); + if (Adapter::in_shutdown()) + return PEP_SYNC_NO_CHANNEL; + PEP_STATUS status = PassphraseCache::config_next_passphrase(); // if the cache has no valid passphrase ask the app diff --git a/locked_queue.hh b/locked_queue.hh index 62bbd10..b390799 100644 --- a/locked_queue.hh +++ b/locked_queue.hh @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include @@ -17,7 +17,7 @@ namespace utility Mutex _mtx; std::condition_variable_any _cv; - std::list _q; + std::deque _q; public: ~locked_queue() @@ -39,14 +39,14 @@ namespace utility } // undefined behavior when queue empty - T& back() + T back() { Lock lg(_mtx); return _q.back(); } // undefined behavior when queue empty - T& front() + T front() { Lock lg(_mtx); return _q.front(); diff --git a/pc_container.hh b/pc_container.hh index 0a37e0c..b3b13d8 100644 --- a/pc_container.hh +++ b/pc_container.hh @@ -17,7 +17,7 @@ enum class PC_State { Illegal = 0, Created = 1, Deleted = 2, Changed = 3 }; // Producer/Consumer container. // -// The "Producer" works on a std::list: inserts, changes, erases elements and +// The "Producer" works on a std::deque: inserts, changes, erases elements and // informs a "Consumer" via a queue about the changes. // // The "Consumer" can poll for changes and process them asynchronously. @@ -36,7 +36,7 @@ public: PC_State state() const noexcept { return PC_State((pdata!=nullptr) + (cdata!=nullptr)*2); } }; - typedef std::list Container; + typedef std::deque Container; typename Container::const_iterator cbegin() const noexcept { return c.cbegin(); } typename Container::const_iterator cend() const noexcept { return c.cend(); }