From 6395c0f72e1486cbe86b25415aa92b7b7d95060a Mon Sep 17 00:00:00 2001 From: Roker Date: Fri, 25 Sep 2020 21:23:50 +0200 Subject: [PATCH 2/3] count number of threads waiting in locked_queue.pop...() --- locked_queue.hh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/locked_queue.hh b/locked_queue.hh index e96faac..ccf45ea 100644 --- a/locked_queue.hh +++ b/locked_queue.hh @@ -15,6 +15,7 @@ namespace utility typedef std::recursive_mutex Mutex; typedef std::unique_lock Lock; + int _waiting = 0; Mutex _mtx; std::condition_variable_any _cv; std::deque _q; @@ -83,11 +84,14 @@ namespace utility bool try_pop_back(T& out, std::chrono::steady_clock::time_point end_time) { Lock L(_mtx); + ++_waiting; if(! _cv.wait_until(L, end_time, [this]{ return !_q.empty(); } ) ) { + --_waiting; return false; } + --_waiting; out = std::move(_q.back()); _q.pop_back(); return true; @@ -98,11 +102,14 @@ namespace utility bool try_pop_front(T& out, std::chrono::steady_clock::time_point end_time) { Lock L(_mtx); + ++_waiting; if(! _cv.wait_until(L, end_time, [this]{ return !_q.empty(); } ) ) { + --_waiting; return false; } + --_waiting; out = std::move(_q.front()); _q.pop_front(); return true; @@ -113,11 +120,14 @@ namespace utility bool try_pop_front(T& out, std::chrono::seconds duration) { Lock L(_mtx); + ++_waiting; if(! _cv.wait_for(L, duration, [this]{ return !_q.empty(); } ) ) { + --_waiting; return false; } + --_waiting; out = std::move(_q.front()); _q.pop_front(); return true; @@ -162,6 +172,13 @@ namespace utility Lock lg(_mtx); return _q.empty(); } + + // returns the number of threads that are waiting in pop_...() or try_pop_...() + int waiting() + { + Lock L(_mtx); + return _waiting; + } }; -} +} // end of namespace utility From 25737863cbc9794e1c7e1ee4039bc723e414c57f Mon Sep 17 00:00:00 2001 From: Jorg Knobloch Date: Fri, 25 Sep 2020 23:49:19 +0200 Subject: [PATCH 3/3] Fixed white-space issues introduced in rev. 25a4d2b6d02f. --- message_cache.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/message_cache.cc b/message_cache.cc index f6d2f7d..eeda4a3 100644 --- a/message_cache.cc +++ b/message_cache.cc @@ -472,12 +472,14 @@ namespace pEp { { ::message *_msg; { - std::lock_guard l(_mtx); _msg = - message_cache._cache.at(cacheID(src)).src; swapContent(src, _msg); + std::lock_guard l(_mtx); + _msg = message_cache._cache.at(cacheID(src)).src; + swapContent(src, _msg); } - ::message *_dst = nullptr; PEP_STATUS status = - ::encrypt_message(session, src, extra, &_dst, enc_format, flags); + ::message *_dst = nullptr; + PEP_STATUS status = ::encrypt_message(session, src, extra, &_dst, + enc_format, flags); *dst = empty_message_copy(_dst); { @@ -502,14 +504,15 @@ namespace pEp { { ::message *_msg; { - std::lock_guard l(_mtx); _msg = - message_cache._cache.at(cacheID(src)).src; swapContent(src, - _msg); + std::lock_guard l(_mtx); + _msg = message_cache._cache.at(cacheID(src)).src; + swapContent(src, _msg); } - ::message *_dst = nullptr; PEP_STATUS status = - ::encrypt_message_for_self(session, target_id, src, extra, &_dst, - enc_format, flags); *dst = empty_message_copy(_dst); + ::message *_dst = nullptr; + PEP_STATUS status = ::encrypt_message_for_self(session, target_id, src, + extra, &_dst, enc_format, flags); + *dst = empty_message_copy(_dst); { std::lock_guard l(_mtx);