EventLoop: new implementation using epoll

Implement an event loop without GLib.
This commit is contained in:
Max Kellermann
2013-08-07 22:16:59 +02:00
parent 342333f72a
commit c1f4f1fdb6
14 changed files with 716 additions and 16 deletions
+20
View File
@@ -29,8 +29,13 @@ IdleMonitor::Cancel()
if (!IsActive())
return;
#ifdef USE_EPOLL
active = false;
loop.RemoveIdle(*this);
#else
g_source_remove(source_id);
source_id = 0;
#endif
}
void
@@ -42,19 +47,32 @@ IdleMonitor::Schedule()
/* already scheduled */
return;
#ifdef USE_EPOLL
active = true;
loop.AddIdle(*this);
#else
source_id = loop.AddIdle(Callback, this);
#endif
}
void
IdleMonitor::Run()
{
assert(loop.IsInside());
#ifdef USE_EPOLL
assert(active);
active = false;
#else
assert(source_id != 0);
source_id = 0;
#endif
OnIdle();
}
#ifndef USE_EPOLL
gboolean
IdleMonitor::Callback(gpointer data)
{
@@ -62,3 +80,5 @@ IdleMonitor::Callback(gpointer data)
monitor.Run();
return false;
}
#endif