diff --git a/callback_dispatcher.cc b/callback_dispatcher.cc index 1c54d47..6f4a3ce 100644 --- a/callback_dispatcher.cc +++ b/callback_dispatcher.cc @@ -29,7 +29,6 @@ namespace pEp { throw std::invalid_argument("messageToSend must be set"); targets.push_back({messageToSend, notifyHandshake, on_startup, shutdown}); - semaphore.go(); } void CallbackDispatcher::remove(::messageToSend_t messageToSend) diff --git a/callback_dispatcher.hh b/callback_dispatcher.hh index 6ced956..17f39e3 100644 --- a/callback_dispatcher.hh +++ b/callback_dispatcher.hh @@ -5,6 +5,7 @@ #include #include "Adapter.hh" #include "Semaphore.hh" +#include "passphrase_cache.hh" namespace pEp { // use this class when implementing a desktop adapter @@ -46,6 +47,8 @@ namespace pEp { PEP_STATUS _messageToSend(::message *msg); PEP_STATUS _notifyHandshake(::pEp_identity *me, ::pEp_identity *partner, ::sync_handshake_signal signal); + + friend const char *PassphraseCache::add(const std::string& passphrase); }; extern CallbackDispatcher callback_dispatcher; diff --git a/passphrase_cache.cc b/passphrase_cache.cc index 2aae276..45e10b1 100644 --- a/passphrase_cache.cc +++ b/passphrase_cache.cc @@ -1,6 +1,7 @@ #include #include "Adapter.hh" #include "passphrase_cache.hh" +#include "callback_dispatcher.hh" pEp::PassphraseCache pEp::passphrase_cache; @@ -35,15 +36,19 @@ namespace pEp { const char *PassphraseCache::add(const std::string& passphrase) { if (!passphrase.empty()) { - std::lock_guard lock(_mtx); - - while (_cache.size() >= _max_size) - _cache.pop_front(); - - _cache.push_back({passphrase, clock::now()}); - auto back = _cache.end(); - assert(!_cache.empty()); - auto result = (--back)->passphrase.c_str(); + const char *result = nullptr; + { + std::lock_guard lock(_mtx); + + while (_cache.size() >= _max_size) + _cache.pop_front(); + + _cache.push_back({passphrase, clock::now()}); + auto back = _cache.end(); + assert(!_cache.empty()); + result = (--back)->passphrase.c_str(); + } + callback_dispatcher.semaphore.go(); return result; }