startup() may throw RuntimeError

sync
Volker Birk 4 years ago
parent 14747c481b
commit c25feca938

@ -29,7 +29,7 @@ namespace pEp {
T *obj = nullptr,
std::function< void (T *) > _startup = nullptr,
std::function< void (T *) > _shutdown = nullptr
);
) throw (RuntimeError);
// returns 'true' when called from the "sync" thread, 'false' otherwise.
bool on_sync_thread();

@ -47,6 +47,7 @@ namespace pEp {
function< void(T *) > _startup,
function< void(T *) > _shutdown
)
throw (RuntimeError)
{
if (messageToSend)
_messageToSend = messageToSend;
@ -59,8 +60,15 @@ namespace pEp {
{
std::lock_guard<std::mutex> lock(m);
if (!_sync_thread)
_sync_thread = new std::thread(sync_thread<T>, obj, _startup, _shutdown);
if (!_sync_thread) {
try {
_sync_thread = new std::thread(sync_thread<T>, obj, _startup, _shutdown);
}
catch (RuntimeError& ex) {
_sync_thread = nullptr;
throw ex;
}
}
}
}
}

Loading…
Cancel
Save