extra callbacks for sync thread

sync
Volker Birk 4 years ago
parent 3d15b8513d
commit e99d28569c

@ -34,6 +34,8 @@ namespace pEp {
namespace Adapter {
messageToSend_t _messageToSend = nullptr;
notifyHandshake_t _notifyHandshake = nullptr;
messageToSend_t _messageToSend_sync = nullptr;
notifyHandshake_t _notifyHandshake_sync = nullptr;
std::thread *_sync_thread = nullptr;
::utility::locked_queue< SYNC_EVENT, &free_Sync_event> q;
@ -87,6 +89,11 @@ namespace pEp {
PEP_SESSION session(session_action action)
{
lock_guard<mutex> lock(m);
bool in_sync;
if (_sync_thread && _sync_thread->get_id() == this_thread::get_id())
in_sync = true;
else
in_sync = false;
thread_local static PEP_SESSION _session = nullptr;
PEP_STATUS status = PEP_STATUS_OK;
@ -100,8 +107,12 @@ namespace pEp {
break;
case init:
if (!_session)
status = ::init(&_session, _messageToSend, _inject_sync_event);
if (!_session) {
if (in_sync && _messageToSend_sync)
status = ::init(&_session, _messageToSend_sync, _inject_sync_event);
else
status = ::init(&_session, _messageToSend, _inject_sync_event);
}
break;
default:
@ -124,4 +135,3 @@ namespace pEp {
}
}
}

@ -21,8 +21,12 @@ namespace pEp {
};
namespace Adapter {
template<class T> void startup(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, T *obj = nullptr,
template<class T> void startup(
messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake,
messageToSend_t messageToSend_sync = nullptr,
notifyHandshake_t notifyHandshake_sync = nullptr,
T *obj = nullptr,
function< void (T *) > _startup = nullptr,
function< void (T *) > _shutdown = nullptr
);

@ -8,6 +8,8 @@ namespace pEp {
namespace Adapter {
extern messageToSend_t _messageToSend;
extern notifyHandshake_t _notifyHandshake;
extern messageToSend_t _messageToSend_sync;
extern notifyHandshake_t _notifyHandshake_sync;
extern std::thread *_sync_thread;
extern ::utility::locked_queue< SYNC_EVENT, &free_Sync_event > q;
@ -33,8 +35,12 @@ namespace pEp {
_shutdown(obj);
}
template< class T > void startup(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, T *obj,
template< class T > void startup(
messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake,
messageToSend_t messageToSend_sync,
notifyHandshake_t notifyHandshake_sync,
T *obj,
function< void(T *) > _startup,
function< void(T *) > _shutdown
)
@ -45,6 +51,12 @@ namespace pEp {
if (notifyHandshake)
_notifyHandshake = notifyHandshake;
if (messageToSend_sync)
_messageToSend_sync = messageToSend_sync;
if (notifyHandshake_sync)
_notifyHandshake_sync = notifyHandshake_sync;
session();
{

@ -1,7 +1,7 @@
// this file is under GNU GPL 3.0, see LICENSE.txt
#pragma once
#ifndef PEP_LOCKED_QUEUE
#define PEP_LOCKED_QUEUE
#include <list>
#include <condition_variable>
@ -9,7 +9,7 @@
namespace utility
{
template<class T, void(*Deleter)(T) = [](T e) { delete e; } >
template<class T, void(*deleter)(T) = [](T e) { delete e; } >
class locked_queue
{
typedef std::recursive_mutex Mutex;
@ -30,7 +30,7 @@ namespace utility
Lock L(_mtx);
for(auto& element : _q)
{
Deleter(element);
deleter(element);
}
_q.clear();
}
@ -134,4 +134,6 @@ namespace utility
return _q.empty();
}
};
};
}
#endif // PEP_LOCKED_QUEUE

Loading…
Cancel
Save