diff --git a/Adapter.cc b/Adapter.cc index 0641fb8..2fcc0ea 100644 --- a/Adapter.cc +++ b/Adapter.cc @@ -27,7 +27,7 @@ namespace pEp { messageToSend_t Adapter::_messageToSend = nullptr; notifyHandshake_t Adapter::_notifyHandshake = nullptr; - std::thread *_sync_thread = nullptr; + std::thread *Adapter::_sync_thread = nullptr; Adapter::Adapter(messageToSend_t messageToSend, notifyHandshake_t notifyHandshake, void *obj) @@ -43,9 +43,9 @@ namespace pEp { { lock_guard lock(mtx()); - if (!_sync_thread) { - _sync_thread = new thread(sync_thread, obj); - _sync_thread->detach(); + if (!Adapter::_sync_thread) { + Adapter::_sync_thread = new thread(sync_thread, obj); + Adapter::_sync_thread->detach(); } } } @@ -81,9 +81,11 @@ namespace pEp { void Adapter::shutdown() { _inject_sync_event(nullptr, nullptr); - _sync_thread->join(); - delete _sync_thread; - _sync_thread = nullptr; + if (Adapter::_sync_thread) { + Adapter::_sync_thread->join(); + delete Adapter::_sync_thread; + Adapter::_sync_thread = nullptr; + } } int Adapter::_inject_sync_event(SYNC_EVENT ev, void *management) diff --git a/Adapter.hh b/Adapter.hh index 44998b6..2bde67a 100644 --- a/Adapter.hh +++ b/Adapter.hh @@ -30,7 +30,7 @@ namespace pEp { session(release); } - void shutdown(); + static void shutdown(); protected: static int _inject_sync_event(SYNC_EVENT ev, void *management); diff --git a/Makefile b/Makefile index 59038b4..ef06afa 100644 --- a/Makefile +++ b/Makefile @@ -10,16 +10,24 @@ CXXFLAGS += -I$(HOME)/include -std=c++14 SOURCE=$(wildcard *.cc) OBJECTS=$(subst .cc,.o,$(SOURCE)) +WITHOUT_TESTS=$(patsubst test%.o,,$(OBJECTS)) all: $(TARGET) %.o: %.cc %.hh $(CXX) $(CXXFLAGS) -c $< -$(TARGET): $(OBJECTS) +$(TARGET): $(WITHOUT_TESTS) ar -rc $@ $^ -.PHONY: clean +.PHONY: clean test clean: - rm -f $(TARGET) $(OBJECTS) + rm -f $(TARGET) $(OBJECTS) *.a test_adapter + +test: test_adapter + ./test_adapter + +test_adapter: $(OBJECTS) + $(CXX) -o $@ -L$(HOME)/lib -lpEpEngine $(OBJECTS) +