Skip to content
Snippets Groups Projects
Commit c587d1e4 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Merge branch 'pierre-luc'

parents 6bd28a4c 466f442b
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "api.h" #include "api.h"
#include "util.h" #include "util.h"
#include "error.h"
namespace DBus { namespace DBus {
...@@ -149,6 +150,8 @@ public: ...@@ -149,6 +150,8 @@ public:
virtual void dispatch(); virtual void dispatch();
virtual void terminate();
private: private:
DefaultMutex _mutex_t; DefaultMutex _mutex_t;
...@@ -157,6 +160,8 @@ private: ...@@ -157,6 +160,8 @@ private:
DefaultMutex _mutex_w; DefaultMutex _mutex_w;
DefaultWatches _watches; DefaultWatches _watches;
int _terminateFd[2];
friend class DefaultTimeout; friend class DefaultTimeout;
friend class DefaultWatch; friend class DefaultWatch;
}; };
......
...@@ -86,6 +86,7 @@ void BusDispatcher::enter() ...@@ -86,6 +86,7 @@ void BusDispatcher::enter()
void BusDispatcher::leave() void BusDispatcher::leave()
{ {
_running = false; _running = false;
terminate();
} }
void BusDispatcher::do_iteration() void BusDispatcher::do_iteration()
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h>
#include <cstdio>
#include <dbus/dbus.h> #include <dbus/dbus.h>
...@@ -97,6 +99,9 @@ void DefaultMutex::unlock() ...@@ -97,6 +99,9 @@ void DefaultMutex::unlock()
DefaultMainLoop::DefaultMainLoop() DefaultMainLoop::DefaultMainLoop()
{ {
if(pipe(_terminateFd) < 0) {
throw ErrorFailed ("unable to create unamed pipe");
}
} }
DefaultMainLoop::~DefaultMainLoop() DefaultMainLoop::~DefaultMainLoop()
...@@ -129,14 +134,22 @@ DefaultMainLoop::~DefaultMainLoop() ...@@ -129,14 +134,22 @@ DefaultMainLoop::~DefaultMainLoop()
ti = tmp; ti = tmp;
} }
close(_terminateFd[0]);
close(_terminateFd[1]);
_mutex_t.unlock(); _mutex_t.unlock();
} }
void DefaultMainLoop::terminate()
{
write(_terminateFd[1], " ", 1);
}
void DefaultMainLoop::dispatch() void DefaultMainLoop::dispatch()
{ {
_mutex_w.lock(); _mutex_w.lock();
int nfd = _watches.size(); int nfd = _watches.size() + 1;
pollfd fds[nfd]; pollfd fds[nfd];
...@@ -152,6 +165,10 @@ void DefaultMainLoop::dispatch() ...@@ -152,6 +165,10 @@ void DefaultMainLoop::dispatch()
} }
} }
fds[nfd].fd = _terminateFd[0];
fds[nfd].events = POLLIN;
fds[nfd].revents = 0;
_mutex_w.unlock(); _mutex_w.unlock();
int wait_min = 10000; int wait_min = 10000;
...@@ -167,7 +184,7 @@ void DefaultMainLoop::dispatch() ...@@ -167,7 +184,7 @@ void DefaultMainLoop::dispatch()
_mutex_t.unlock(); _mutex_t.unlock();
poll (fds, nfd, wait_min); poll (fds, nfd+1, wait_min);
timeval now; timeval now;
gettimeofday (&now, NULL); gettimeofday (&now, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment