...
authorVolker Birk <vb@pep.foundation>
Thu, 04 Oct 2018 17:30:34 +0200
changeset 151b8722ea1a42
parent 14 f88f7ccd1b7a
child 16 19b7ea5e3362
...
Adapter.cc
Adapter.hh
Makefile
     1.1 --- a/Adapter.cc	Thu Oct 04 14:07:10 2018 +0200
     1.2 +++ b/Adapter.cc	Thu Oct 04 17:30:34 2018 +0200
     1.3 @@ -27,7 +27,7 @@
     1.4  
     1.5      messageToSend_t Adapter::_messageToSend = nullptr;
     1.6      notifyHandshake_t Adapter::_notifyHandshake = nullptr;
     1.7 -    std::thread *_sync_thread = nullptr;
     1.8 +    std::thread *Adapter::_sync_thread = nullptr;
     1.9  
    1.10      Adapter::Adapter(messageToSend_t messageToSend,
    1.11              notifyHandshake_t notifyHandshake, void *obj)
    1.12 @@ -43,9 +43,9 @@
    1.13          {
    1.14              lock_guard<mutex> lock(mtx());
    1.15  
    1.16 -            if (!_sync_thread) {
    1.17 -                _sync_thread = new thread(sync_thread, obj);
    1.18 -                _sync_thread->detach();
    1.19 +            if (!Adapter::_sync_thread) {
    1.20 +                Adapter::_sync_thread = new thread(sync_thread, obj);
    1.21 +                Adapter::_sync_thread->detach();
    1.22              }
    1.23          }
    1.24      }
    1.25 @@ -81,9 +81,11 @@
    1.26      void Adapter::shutdown()
    1.27      {
    1.28          _inject_sync_event(nullptr, nullptr);
    1.29 -        _sync_thread->join();
    1.30 -        delete _sync_thread;
    1.31 -        _sync_thread = nullptr;
    1.32 +        if (Adapter::_sync_thread) {
    1.33 +            Adapter::_sync_thread->join();
    1.34 +            delete Adapter::_sync_thread;
    1.35 +            Adapter::_sync_thread = nullptr;
    1.36 +        }
    1.37      }
    1.38  
    1.39      int Adapter::_inject_sync_event(SYNC_EVENT ev, void *management)
     2.1 --- a/Adapter.hh	Thu Oct 04 14:07:10 2018 +0200
     2.2 +++ b/Adapter.hh	Thu Oct 04 17:30:34 2018 +0200
     2.3 @@ -30,7 +30,7 @@
     2.4                  session(release);
     2.5              }
     2.6  
     2.7 -            void shutdown();
     2.8 +            static void shutdown();
     2.9  
    2.10          protected:
    2.11              static int _inject_sync_event(SYNC_EVENT ev, void *management);
     3.1 --- a/Makefile	Thu Oct 04 14:07:10 2018 +0200
     3.2 +++ b/Makefile	Thu Oct 04 17:30:34 2018 +0200
     3.3 @@ -10,16 +10,24 @@
     3.4  
     3.5  SOURCE=$(wildcard *.cc)
     3.6  OBJECTS=$(subst .cc,.o,$(SOURCE))
     3.7 +WITHOUT_TESTS=$(patsubst test%.o,,$(OBJECTS))
     3.8  
     3.9  all: $(TARGET)
    3.10  
    3.11  %.o: %.cc %.hh
    3.12  	$(CXX) $(CXXFLAGS) -c $<
    3.13  
    3.14 -$(TARGET): $(OBJECTS)
    3.15 +$(TARGET): $(WITHOUT_TESTS)
    3.16  	ar -rc $@ $^
    3.17  
    3.18 -.PHONY: clean
    3.19 +.PHONY: clean test
    3.20  
    3.21  clean:
    3.22 -	rm -f $(TARGET) $(OBJECTS)
    3.23 +	rm -f $(TARGET) $(OBJECTS) *.a test_adapter
    3.24 +
    3.25 +test: test_adapter
    3.26 +	./test_adapter
    3.27 +
    3.28 +test_adapter: $(OBJECTS)
    3.29 +	$(CXX) -o $@ -L$(HOME)/lib -lpEpEngine $(OBJECTS)
    3.30 +