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 @@
#include "api.h"
#include "util.h"
#include "error.h"
namespace DBus {
......@@ -149,6 +150,8 @@ public:
virtual void dispatch();
virtual void terminate();
private:
DefaultMutex _mutex_t;
......@@ -156,6 +159,8 @@ private:
DefaultMutex _mutex_w;
DefaultWatches _watches;
int _terminateFd[2];
friend class DefaultTimeout;
friend class DefaultWatch;
......
......@@ -86,6 +86,7 @@ void BusDispatcher::enter()
void BusDispatcher::leave()
{
_running = false;
terminate();
}
void BusDispatcher::do_iteration()
......
......@@ -30,6 +30,8 @@
#include <sys/poll.h>
#include <sys/time.h>
#include <unistd.h>
#include <cstdio>
#include <dbus/dbus.h>
......@@ -97,6 +99,9 @@ void DefaultMutex::unlock()
DefaultMainLoop::DefaultMainLoop()
{
if(pipe(_terminateFd) < 0) {
throw ErrorFailed ("unable to create unamed pipe");
}
}
DefaultMainLoop::~DefaultMainLoop()
......@@ -129,15 +134,23 @@ DefaultMainLoop::~DefaultMainLoop()
ti = tmp;
}
close(_terminateFd[0]);
close(_terminateFd[1]);
_mutex_t.unlock();
}
void DefaultMainLoop::dispatch()
void DefaultMainLoop::terminate()
{
_mutex_w.lock();
write(_terminateFd[1], " ", 1);
}
int nfd = _watches.size();
void DefaultMainLoop::dispatch()
{
_mutex_w.lock();
int nfd = _watches.size() + 1;
pollfd fds[nfd];
DefaultWatches::iterator wi = _watches.begin();
......@@ -152,6 +165,10 @@ void DefaultMainLoop::dispatch()
}
}
fds[nfd].fd = _terminateFd[0];
fds[nfd].events = POLLIN;
fds[nfd].revents = 0;
_mutex_w.unlock();
int wait_min = 10000;
......@@ -167,7 +184,7 @@ void DefaultMainLoop::dispatch()
_mutex_t.unlock();
poll (fds, nfd, wait_min);
poll (fds, nfd+1, wait_min);
timeval now;
gettimeofday (&now, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment