Volker Birk 6 years ago
parent
commit
fad58207d7
  1. 30
      Adapter.hxx

30
Adapter.hxx

@ -17,8 +17,8 @@ namespace pEp {
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold); SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold);
std::exception_ptr _ex; static std::exception_ptr _ex;
bool lpa_register_done = false; static bool register_done = false;
template< class T > void sync_thread(T *obj, function< void(T *) > _startup, function< void(T *) > _shutdown) template< class T > void sync_thread(T *obj, function< void(T *) > _startup, function< void(T *) > _shutdown)
{ {
@ -34,11 +34,11 @@ namespace pEp {
_notifyHandshake, _retrieve_next_sync_event); _notifyHandshake, _retrieve_next_sync_event);
try { try {
throw_status(status); throw_status(status);
lpa_register_done = true; register_done = true;
} }
catch (...) { catch (...) {
_ex = std::current_exception(); _ex = std::current_exception();
lpa_register_done = true; register_done = true;
return; return;
} }
} }
@ -69,19 +69,15 @@ namespace pEp {
session(); session();
{ if (!_sync_thread) {
std::lock_guard<std::mutex> lock(m); register_done = false;
_sync_thread = new std::thread(sync_thread<T>, obj, _startup, _shutdown);
if (!_sync_thread) { while (!register_done)
lpa_register_done = false; std::this_thread::sleep_for(std::chrono::milliseconds(100));
_sync_thread = new std::thread(sync_thread<T>, obj, _startup, _shutdown);
while (!lpa_register_done) if (_ex) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); _sync_thread = nullptr;
std::rethrow_exception(_ex);
if (_ex) {
_sync_thread = nullptr;
std::rethrow_exception(_ex);
}
} }
} }
} }

Loading…
Cancel
Save