aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/TimeoutMonitor.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-07 22:16:59 +0200
committerMax Kellermann <max@duempel.org>2013-08-10 13:54:23 +0200
commitc1f4f1fdb64d97b5c3461723a8482ca64efea30e (patch)
tree54c8a9c1466beec0dbfac1c0b5f5773060c1aa2b /src/event/TimeoutMonitor.cxx
parent342333f72a484e9f394026666c4b20e54dc9b756 (diff)
downloadmpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.tar.gz
mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.tar.xz
mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.zip
EventLoop: new implementation using epoll
Implement an event loop without GLib.
Diffstat (limited to 'src/event/TimeoutMonitor.cxx')
-rw-r--r--src/event/TimeoutMonitor.cxx25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/event/TimeoutMonitor.cxx b/src/event/TimeoutMonitor.cxx
index 8636292ac..cffad6b92 100644
--- a/src/event/TimeoutMonitor.cxx
+++ b/src/event/TimeoutMonitor.cxx
@@ -24,10 +24,15 @@
void
TimeoutMonitor::Cancel()
{
- if (source != nullptr) {
+ if (IsActive()) {
+#ifdef USE_EPOLL
+ active = false;
+ loop.CancelTimer(*this);
+#else
g_source_destroy(source);
g_source_unref(source);
source = nullptr;
+#endif
}
}
@@ -35,23 +40,39 @@ void
TimeoutMonitor::Schedule(unsigned ms)
{
Cancel();
+
+#ifdef USE_EPOLL
+ active = true;
+ loop.AddTimer(*this, ms);
+#else
source = loop.AddTimeout(ms, Callback, this);
+#endif
}
void
TimeoutMonitor::ScheduleSeconds(unsigned s)
{
Cancel();
+
+#ifdef USE_EPOLL
+ Schedule(s * 1000u);
+#else
source = loop.AddTimeoutSeconds(s, Callback, this);
+#endif
}
void
TimeoutMonitor::Run()
{
+#ifndef USE_EPOLL
Cancel();
+#endif
+
OnTimeout();
}
+#ifndef USE_EPOLL
+
gboolean
TimeoutMonitor::Callback(gpointer data)
{
@@ -59,3 +80,5 @@ TimeoutMonitor::Callback(gpointer data)
monitor.Run();
return false;
}
+
+#endif