Browse Source

simplify

sync
Volker Birk 7 years ago
parent
commit
47d8cfbd97
  1. 14
      Adapter.cc
  2. 4
      Adapter.hh
  3. 10
      Adapter.hxx
  4. 6
      libpEpAdapter/libpEpAdapter.vcxproj.filters

14
Adapter.cc

@ -86,14 +86,18 @@ namespace pEp {
return q.pop_front(); return q.pop_front();
} }
PEP_SESSION session(session_action action) bool on_sync_thread()
{ {
lock_guard<mutex> lock(m);
bool in_sync;
if (_sync_thread && _sync_thread->get_id() == this_thread::get_id()) if (_sync_thread && _sync_thread->get_id() == this_thread::get_id())
in_sync = true; return true;
else else
in_sync = false; return false;
}
PEP_SESSION session(session_action action)
{
lock_guard<mutex> lock(m);
bool in_sync = on_sync_thread();
thread_local static PEP_SESSION _session = nullptr; thread_local static PEP_SESSION _session = nullptr;
PEP_STATUS status = PEP_STATUS_OK; PEP_STATUS status = PEP_STATUS_OK;

4
Adapter.hh

@ -24,13 +24,13 @@ namespace pEp {
template<class T> void startup( template<class T> void startup(
messageToSend_t messageToSend, messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, notifyHandshake_t notifyHandshake,
messageToSend_t messageToSend_sync = nullptr,
notifyHandshake_t notifyHandshake_sync = nullptr,
T *obj = nullptr, T *obj = nullptr,
function< void (T *) > _startup = nullptr, function< void (T *) > _startup = nullptr,
function< void (T *) > _shutdown = nullptr function< void (T *) > _shutdown = nullptr
); );
bool on_sync_thread();
enum session_action { enum session_action {
init, init,
release release

10
Adapter.hxx

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

6
libpEpAdapter/libpEpAdapter.vcxproj.filters

@ -26,14 +26,14 @@
<ClInclude Include="..\Adapter.hh"> <ClInclude Include="..\Adapter.hh">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Adapter.hxx">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\locked_queue.hh"> <ClInclude Include="..\locked_queue.hh">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\pc_container.hh"> <ClInclude Include="..\pc_container.hh">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Adapter.hxx">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
Loading…
Cancel
Save