Browse Source

...

PYADPT-55
Volker Birk 7 years ago
parent
commit
7421773c1e
  1. 5
      .hgignore
  2. 4
      setup.py
  3. 6
      src/adapter.cc
  4. 14
      src/adapter.hh
  5. 1
      src/pEpmodule.cc
  6. 4
      src/user_interface.cc

5
.hgignore

@ -1,8 +1,9 @@
syntax: glob syntax: glob
*.swp *.swp
*.o
*.so
ws ws
tags tags
.DS_Store .DS_Store
pEp.egg-info
dist
build

4
setup.py

@ -62,9 +62,9 @@ module_pEp = Extension('pEp',
setup( setup(
name='p≡p Python adapter', name='pEp',
version='2.0', version='2.0',
description='Provides a Python module giving access to p≡p engine', description='p≡p for Python',
author="Volker Birk", author="Volker Birk",
author_email="vb@pep-project.org", author_email="vb@pep-project.org",
ext_modules=[module_pEp,], ext_modules=[module_pEp,],

6
src/adapter.cc

@ -18,7 +18,7 @@ namespace pEp {
PEP_SESSION Adapter::session(session_action action) PEP_SESSION Adapter::session(session_action action)
{ {
lock_guard<mutex> lock(mtx); lock_guard<mutex> lock(mtx());
thread_local static PEP_SESSION _session = nullptr; thread_local static PEP_SESSION _session = nullptr;
thread_local int booked = 0; thread_local int booked = 0;
@ -56,7 +56,7 @@ namespace pEp {
PyObject *Adapter::ui_object(PyObject *value) PyObject *Adapter::ui_object(PyObject *value)
{ {
lock_guard<mutex> lock(mtx); lock_guard<mutex> lock(mtx());
static PyObject *obj = nullptr; static PyObject *obj = nullptr;
if (value) if (value)
obj = value; obj = value;
@ -80,7 +80,7 @@ namespace pEp {
} }
try { try {
q.push_front(ev); queue().push_front(ev);
} }
catch (exception&) { catch (exception&) {
return 1; return 1;

14
src/adapter.hh

@ -28,7 +28,11 @@ namespace pEp {
}; };
PEP_SESSION session(session_action action = none); PEP_SESSION session(session_action action = none);
static ::utility::locked_queue< SYNC_EVENT >& queue()
{
static ::utility::locked_queue< SYNC_EVENT > q; static ::utility::locked_queue< SYNC_EVENT > q;
return q;
}
protected: protected:
static PyObject *ui_object(PyObject *value = nullptr); static PyObject *ui_object(PyObject *value = nullptr);
@ -36,11 +40,11 @@ namespace pEp {
static int _inject_sync_event(SYNC_EVENT ev, void *management); static int _inject_sync_event(SYNC_EVENT ev, void *management);
private: private:
static mutex mtx; static mutex& mtx()
{
// non copyable static mutex m;
Adapter(const Adapter&) = delete; return m;
Adapter& operator= (const Adapter&) = delete; }
friend class UserInterface_callback; friend class UserInterface_callback;
}; };

1
src/pEpmodule.cc

@ -9,6 +9,7 @@
#include "basic_api.hh" #include "basic_api.hh"
#include "message_api.hh" #include "message_api.hh"
#include "user_interface.hh" #include "user_interface.hh"
#include "adapter.hh"
#include <mutex> #include <mutex>

4
src/user_interface.cc

@ -51,9 +51,9 @@ namespace pEp {
SYNC_EVENT UserInterface::retrieve_next_sync_event(void *management) SYNC_EVENT UserInterface::retrieve_next_sync_event(void *management)
{ {
while (adapter.q.empty()) while (adapter.queue().empty())
nanosleep((const struct timespec[]){{0, 100000000L}}, NULL); nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
return adapter.q.pop_front(); return adapter.queue().pop_front();
} }
void UserInterface_callback::notifyHandshake( void UserInterface_callback::notifyHandshake(

Loading…
Cancel
Save