]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Fri, 20 Jul 2012 15:18:56 +0000 (17:18 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 20 Jul 2012 15:18:56 +0000 (17:18 +0200)
server/Client.cc
server/Client.h

index 6a4ba94c4ecac56a7655b2b4aeff16149eed597e..f02dd5420f978d42f315d8c106fa0419b5999a0b 100644 (file)
@@ -32,16 +32,20 @@ bool contains(const ListType& l, const Type& value)
 
 
 Client::Client(const string& name)
-    : name(name)
+    : name(name), stop(false)
 {
-    c = new boost::condition_variable;
-    t = NULL;
 }
 
 
 Client::~Client()
 {
-    // TODO
+    boost::unique_lock<boost::mutex> lock(mutex);
+    stop = true;
+    lock.unlock();
+
+    condition.notify_all();
+
+    thread.join();             // TODO this can block
 }
 
 
@@ -96,32 +100,34 @@ Client::has_lock(const string& config_name) const
 void
 Client::add_task(DBus::Connection& conn, DBus::Message& msg)
 {
-    if (!t)
-       t = new boost::thread(boost::bind(&Client::worker, this));
+    if (thread.get_id() == boost::thread::id())
+       thread = boost::thread(boost::bind(&Client::worker, this));
 
-    boost::unique_lock<boost::mutex> l(m);
+    boost::unique_lock<boost::mutex> lock(mutex);
     tasks.push(Task(conn, msg));
-    l.unlock();
+    lock.unlock();
 
-    c->notify_one();
+    condition.notify_one();
 }
 
 
-
 void
 Client::worker()
 {
     while (true)
     {
-        boost::unique_lock<boost::mutex> l(m);
+       boost::unique_lock<boost::mutex> lock(mutex);
+
+       while (tasks.empty() && !stop)
+           condition.wait(lock);
 
-        while (tasks.empty())
-            c->wait(l);
+       if (stop)
+           break;
 
-        Task task = tasks.front();
-        tasks.pop();
+       Task task = tasks.front();
+       tasks.pop();
 
-        l.unlock();
+       lock.unlock();
 
        dispatch(task.conn, task.msg);
     }
index 2f171a105c2e0cc9e43613efe062a9069b4e9716..149ac7332ae743f0cf382abbb3da01b730924810 100644 (file)
@@ -120,10 +120,10 @@ public:
        DBus::Message msg;
     };
 
-    boost::condition_variable* c;
-    boost::mutex m;
-    boost::thread* t;
-
+    boost::condition_variable condition;
+    boost::mutex mutex;
+    boost::thread thread;
+    bool stop;
     queue<Task> tasks;
 
     void add_task(DBus::Connection& conn, DBus::Message& msg);