diff --git a/Adapter.cc b/Adapter.cc index 101b796..599edd9 100644 --- a/Adapter.cc +++ b/Adapter.cc @@ -30,7 +30,7 @@ namespace pEp { std::thread *_sync_thread = nullptr; Adapter::Adapter(messageToSend_t messageToSend, - notifyHandshake_t notifyHandshake) + notifyHandshake_t notifyHandshake, void *obj) { if (messageToSend) _messageToSend = messageToSend; @@ -44,7 +44,7 @@ namespace pEp { lock_guard lock(mtx()); if (!_sync_thread) - _sync_thread = new thread(); + _sync_thread = new thread(sync_thread, obj); } } @@ -118,16 +118,17 @@ namespace pEp { return queue().pop_front(); } - void Adapter::sync_thread() + void Adapter::sync_thread(void *obj) { PEP_STATUS status = register_sync_callbacks(session(), nullptr, _notifyHandshake, _retrieve_next_sync_event); throw_status(status); - do_sync_protocol(session(), nullptr); + do_sync_protocol(session(), obj); unregister_sync_callbacks(session()); session(release); + _sync_thread = nullptr; } } diff --git a/Adapter.hh b/Adapter.hh index 5919a97..ac9e7da 100644 --- a/Adapter.hh +++ b/Adapter.hh @@ -17,7 +17,7 @@ namespace pEp { public: Adapter(messageToSend_t messageToSend, - notifyHandshake_t notifyHandshake); + notifyHandshake_t notifyHandshake, void *obj = nullptr); virtual ~Adapter() { } enum session_action { @@ -35,7 +35,7 @@ namespace pEp { protected: static int _inject_sync_event(SYNC_EVENT ev, void *management); static SYNC_EVENT _retrieve_next_sync_event(void *management, time_t threshold); - static void sync_thread(); + static void sync_thread(void *obj); private: static std::mutex& mtx()