|
@ -38,17 +38,14 @@ namespace pEp { |
|
|
namespace Adapter { |
|
|
namespace Adapter { |
|
|
messageToSend_t _messageToSend = nullptr; |
|
|
messageToSend_t _messageToSend = nullptr; |
|
|
notifyHandshake_t _notifyHandshake = nullptr; |
|
|
notifyHandshake_t _notifyHandshake = nullptr; |
|
|
std::thread *_sync_thread = nullptr; |
|
|
std::thread _sync_thread; |
|
|
|
|
|
|
|
|
::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > q; |
|
|
::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > q; |
|
|
std::mutex m; |
|
|
std::mutex m; |
|
|
|
|
|
|
|
|
std::thread::id sync_thread_id() |
|
|
std::thread::id sync_thread_id() |
|
|
{ |
|
|
{ |
|
|
if (_sync_thread) |
|
|
return _sync_thread.get_id(); |
|
|
return _sync_thread->get_id(); |
|
|
|
|
|
else |
|
|
|
|
|
return std::thread::id(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int _inject_sync_event(SYNC_EVENT ev, void *management) |
|
|
int _inject_sync_event(SYNC_EVENT ev, void *management) |
|
@ -65,21 +62,6 @@ namespace pEp { |
|
|
catch (exception&) { |
|
|
catch (exception&) { |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
if (ev == nullptr) { |
|
|
|
|
|
if (!on_sync_thread()) { |
|
|
|
|
|
if(_sync_thread->joinable()) { |
|
|
|
|
|
pEpLog("Waiting for Sync thread to join..."); |
|
|
|
|
|
_sync_thread->join(); |
|
|
|
|
|
delete _sync_thread; |
|
|
|
|
|
_sync_thread = nullptr; |
|
|
|
|
|
pEpLog("...thread joined"); |
|
|
|
|
|
q.clear(); |
|
|
|
|
|
} else { |
|
|
|
|
|
//FATAL
|
|
|
|
|
|
pEpLog("FATAL: sync thread not joinable/detached"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -102,10 +84,7 @@ namespace pEp { |
|
|
|
|
|
|
|
|
bool on_sync_thread() |
|
|
bool on_sync_thread() |
|
|
{ |
|
|
{ |
|
|
if (_sync_thread && _sync_thread->get_id() == this_thread::get_id()) |
|
|
return _sync_thread.get_id() == this_thread::get_id(); |
|
|
return true; |
|
|
|
|
|
else |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PEP_SESSION session(session_action action) |
|
|
PEP_SESSION session(session_action action) |
|
@ -140,15 +119,16 @@ namespace pEp { |
|
|
void shutdown() |
|
|
void shutdown() |
|
|
{ |
|
|
{ |
|
|
pEpLog("called"); |
|
|
pEpLog("called"); |
|
|
if (_sync_thread) { |
|
|
if (_sync_thread.joinable()) { |
|
|
pEpLog("sync_is_running - injecting null event"); |
|
|
pEpLog("sync_is_running - injecting null event"); |
|
|
_inject_sync_event(nullptr, nullptr); |
|
|
_inject_sync_event(nullptr, nullptr); |
|
|
|
|
|
_sync_thread.join(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool is_sync_running() |
|
|
bool is_sync_running() |
|
|
{ |
|
|
{ |
|
|
return _sync_thread != nullptr; |
|
|
return _sync_thread.joinable(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool in_shutdown() |
|
|
bool in_shutdown() |
|
|