From c1f4f1fdb64d97b5c3461723a8482ca64efea30e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 7 Aug 2013 22:16:59 +0200 Subject: EventLoop: new implementation using epoll Implement an event loop without GLib. --- src/event/TimeoutMonitor.cxx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/event/TimeoutMonitor.cxx') 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 -- cgit v1.2.3