From 7421773c1e87b24c68ccfec33ea66ab29b2d9116 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Wed, 29 Aug 2018 19:20:32 +0200 Subject: [PATCH] ... --- .hgignore | 5 +++-- setup.py | 4 ++-- src/adapter.cc | 6 +++--- src/adapter.hh | 16 ++++++++++------ src/pEpmodule.cc | 1 + src/user_interface.cc | 4 ++-- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.hgignore b/.hgignore index b526187..c910687 100644 --- a/.hgignore +++ b/.hgignore @@ -1,8 +1,9 @@ syntax: glob *.swp -*.o -*.so ws tags .DS_Store +pEp.egg-info +dist +build diff --git a/setup.py b/setup.py index 98eb758..1b7baf9 100644 --- a/setup.py +++ b/setup.py @@ -62,9 +62,9 @@ module_pEp = Extension('pEp', setup( - name='p≡p Python adapter', + name='pEp', version='2.0', - description='Provides a Python module giving access to p≡p engine', + description='p≡p for Python', author="Volker Birk", author_email="vb@pep-project.org", ext_modules=[module_pEp,], diff --git a/src/adapter.cc b/src/adapter.cc index 03b7142..1831c3a 100644 --- a/src/adapter.cc +++ b/src/adapter.cc @@ -18,7 +18,7 @@ namespace pEp { PEP_SESSION Adapter::session(session_action action) { - lock_guard lock(mtx); + lock_guard lock(mtx()); thread_local static PEP_SESSION _session = nullptr; thread_local int booked = 0; @@ -56,7 +56,7 @@ namespace pEp { PyObject *Adapter::ui_object(PyObject *value) { - lock_guard lock(mtx); + lock_guard lock(mtx()); static PyObject *obj = nullptr; if (value) obj = value; @@ -80,7 +80,7 @@ namespace pEp { } try { - q.push_front(ev); + queue().push_front(ev); } catch (exception&) { return 1; diff --git a/src/adapter.hh b/src/adapter.hh index 4abedd7..256d05f 100644 --- a/src/adapter.hh +++ b/src/adapter.hh @@ -28,7 +28,11 @@ namespace pEp { }; PEP_SESSION session(session_action action = none); - static ::utility::locked_queue< SYNC_EVENT > q; + static ::utility::locked_queue< SYNC_EVENT >& queue() + { + static ::utility::locked_queue< SYNC_EVENT > q; + return q; + } protected: static PyObject *ui_object(PyObject *value = nullptr); @@ -36,11 +40,11 @@ namespace pEp { static int _inject_sync_event(SYNC_EVENT ev, void *management); private: - static mutex mtx; - - // non copyable - Adapter(const Adapter&) = delete; - Adapter& operator= (const Adapter&) = delete; + static mutex& mtx() + { + static mutex m; + return m; + } friend class UserInterface_callback; }; diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index b1bb0eb..a5b45a2 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -9,6 +9,7 @@ #include "basic_api.hh" #include "message_api.hh" #include "user_interface.hh" +#include "adapter.hh" #include diff --git a/src/user_interface.cc b/src/user_interface.cc index 198dc78..e3ee6a8 100644 --- a/src/user_interface.cc +++ b/src/user_interface.cc @@ -51,9 +51,9 @@ namespace pEp { SYNC_EVENT UserInterface::retrieve_next_sync_event(void *management) { - while (adapter.q.empty()) + while (adapter.queue().empty()) nanosleep((const struct timespec[]){{0, 100000000L}}, NULL); - return adapter.q.pop_front(); + return adapter.queue().pop_front(); } void UserInterface_callback::notifyHandshake(