[Pkg-running-devel] [antpm] 19/48: lqueue: implement logic to wait for lqueue3 even loop to finish

Kristof Ralovich ralovich-guest at moszumanska.debian.org
Mon Aug 11 10:10:32 UTC 2014


This is an automated email from the git hooks/post-receive script.

ralovich-guest pushed a commit to branch upstream
in repository antpm.

commit 5f83506a8c4c4e1c913a5ed572842db4f76d7fa6
Author: RALOVICH, Kristof <tade60 at freemail.hu>
Date:   Wed Mar 26 13:48:27 2014 +0100

    lqueue: implement logic to wait for lqueue3 even loop to finish
---
 src/lqueue.hpp | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/src/lqueue.hpp b/src/lqueue.hpp
index c2223e7..042c84c 100644
--- a/src/lqueue.hpp
+++ b/src/lqueue.hpp
@@ -94,33 +94,29 @@ public:
   typedef boost::function<bool (std::vector<DataType>&)> Listener2;
   typedef lqueue2<DataType>                              Super;
 
-  struct ListenerProc
-  {
-    void operator() (lqueue3* This)
-    {
-      This->eventLoop();
-    }
-  };
-
-
-  lqueue3(bool eventLoopInBgTh = true)
+  lqueue3()
     : stop(false)
+    , started(false)
+    , stopped(false)
   {
-    if(eventLoopInBgTh)
-      th_listener.reset( new boost::thread(lp, this) );
   }
 
   ~lqueue3()
   {
-    stop = true;
-    if(th_listener.get())
-      th_listener->join();
+    kill();
   }
 
   void
   kill()
   {
     stop = true;
+    if(started)
+    {
+      while(!stopped)
+      {
+        boost::thread::yield();
+      }
+    }
   }
 
   void
@@ -132,6 +128,8 @@ public:
 public:
   void eventLoop()
   {
+    assert(!started);
+    started = true;
     while(!stop)
     {
       boost::unique_lock<boost::mutex> lock(Super::m_mtx);
@@ -155,17 +153,18 @@ public:
       if(mCallback)
         /*bool rv =*/ mCallback(v);
     }
+    stopped = true;
   }
 
 protected:
-  ListenerProc lp;
-  boost::scoped_ptr<boost::thread> th_listener;
   volatile bool stop;
+  volatile bool started;
+  volatile bool stopped;
   Listener2 mCallback;
 };
 
 
-// implements poll-able pop consumer
+/// implements poll-able pop consumer
 template < class DataType>
 class lqueue4 : public lqueue2<DataType>
 {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/antpm.git



More information about the Pkg-running-devel mailing list