clean shutdown in sync_thread

sync
Volker Birk 3 years ago
parent c6352281f8
commit 4b9fdbba02

@ -51,13 +51,8 @@ namespace pEp {
return 1;
}
if (ev == nullptr) {
if (!on_sync_thread()) {
if (_sync_thread) {
_sync_thread->join();
delete _sync_thread;
_sync_thread = nullptr;
}
}
if (!on_sync_thread())
_sync_thread->join();
q.clear();
}
return 0;
@ -114,10 +109,8 @@ namespace pEp {
void shutdown()
{
if (_sync_thread) {
if (_sync_thread)
_inject_sync_event(nullptr, nullptr);
}
session(release);
}
bool is_sync_running()
@ -126,3 +119,4 @@ namespace pEp {
}
}
}

@ -25,6 +25,7 @@ namespace pEp {
template< class T > void sync_thread(T *obj, function< void(T *) > _startup, function< void(T *) > _shutdown)
{
_ex = nullptr;
assert(_messageToSend);
assert(_notifyHandshake);
if (obj && _startup)
@ -53,6 +54,12 @@ namespace pEp {
if (obj && _shutdown)
_shutdown(obj);
if (_sync_thread) {
_sync_thread->detach();
delete _sync_thread;
_sync_thread = nullptr;
}
}
template< class T > void startup(
@ -79,6 +86,7 @@ namespace pEp {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (_ex) {
delete _sync_thread;
_sync_thread = nullptr;
std::rethrow_exception(_ex);
}
@ -86,3 +94,4 @@ namespace pEp {
}
}
}

Loading…
Cancel
Save