From 3868ee64ce91f8c09b2ff3e3ba3d9da1930bd118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 5 Oct 2016 13:15:04 +0200 Subject: [PATCH] Sketch the missing driver API functions and avoid virtual function calls. The individual interface getters are now overridden in the final sub classes to avoid virtual calls whenever the final type is used. --- source/eventcore/driver.d | 11 ++++++++++- source/eventcore/drivers/epoll.d | 10 ++++++++++ source/eventcore/drivers/posix.d | 21 +++++++++++++-------- source/eventcore/drivers/select.d | 8 ++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/source/eventcore/driver.d b/source/eventcore/driver.d index d202377..837d256 100644 --- a/source/eventcore/driver.d +++ b/source/eventcore/driver.d @@ -12,6 +12,7 @@ interface EventDriver { @property EventDriverSockets sockets(); @property EventDriverTimers udp(); @property EventDriverEvents events(); + @property EventDriverSignals signals(); @property EventDriverWatchers watchers(); } @@ -143,6 +144,12 @@ interface EventDriverEvents { void cancelWaitForEvent(EventID event, EventCallback on_event); } +interface EventDriverSignals { +@safe: /*@nogc:*/ nothrow: + //void waitForSignal(int sig, SignalCallback on_signal); + //void cancelWaitForSignal(sig); +} + interface EventDriverTimers { @safe: /*@nogc:*/ nothrow: /** @@ -168,7 +175,9 @@ interface EventDriverTimers { interface EventDriverWatchers { @safe: /*@nogc:*/ nothrow: - + //WatcherID watchDirectory(Path path, bool recursive); + //void waitForChanges(WatcherID watcher, FileChangesCallback callback); + //void cancelWaitForChanges(WatcherID watcher); } diff --git a/source/eventcore/drivers/epoll.d b/source/eventcore/drivers/epoll.d index 78dedd8..7205555 100644 --- a/source/eventcore/drivers/epoll.d +++ b/source/eventcore/drivers/epoll.d @@ -29,6 +29,16 @@ final class EpollEventDriver : PosixEventDriver { m_events.length = 100; } + nothrow @safe { + override @property EpollEventDriver core() { return this; } + override @property EpollEventDriver files() { return this; } + override @property EpollEventDriver sockets() { return this; } + override @property EpollEventDriver udp() { return this; } + override @property EpollEventDriver events() { return this; } + override @property EpollEventDriver signals() { return this; } + override @property EpollEventDriver watchers() { return this; } + } + override bool doProcessEvents(Duration timeout) @trusted { import std.algorithm : min; diff --git a/source/eventcore/drivers/posix.d b/source/eventcore/drivers/posix.d index 5f5f7f5..65e91bd 100644 --- a/source/eventcore/drivers/posix.d +++ b/source/eventcore/drivers/posix.d @@ -36,8 +36,11 @@ private long currStdTime() return Clock.currStdTime; } -abstract class PosixEventDriver : EventDriver, EventDriverCore, EventDriverFiles, EventDriverSockets, EventDriverTimers, EventDriverEvents, EventDriverWatchers { - @safe: /*@nogc:*/ nothrow: +abstract class PosixEventDriver : EventDriver, + EventDriverCore, EventDriverFiles, EventDriverSockets, EventDriverTimers, + EventDriverEvents, EventDriverSignals, EventDriverWatchers +{ +@safe: /*@nogc:*/ nothrow: private { ChoppedVector!FDSlot m_fds; @@ -54,12 +57,14 @@ abstract class PosixEventDriver : EventDriver, EventDriverCore, EventDriverFiles //startNotify!(EventType.read)(m_wakeupEvent, null); // should already be caught by registerFD } - @property PosixEventDriver core() { return this; } - @property PosixEventDriver files() { return this; } - @property PosixEventDriver sockets() { return this; } - @property PosixEventDriver udp() { return this; } - @property PosixEventDriver events() { return this; } - @property PosixEventDriver watchers() { return this; } + // force overriding these in the (final) sub classes to avoid virtual calls + abstract override @property PosixEventDriver core(); + abstract override @property PosixEventDriver files(); + abstract override @property PosixEventDriver sockets(); + abstract override @property PosixEventDriver udp(); + abstract override @property PosixEventDriver events(); + abstract override @property PosixEventDriver signals(); + abstract override @property PosixEventDriver watchers(); mixin DefaultTimerImpl!(); diff --git a/source/eventcore/drivers/select.d b/source/eventcore/drivers/select.d index a6a1589..ede2a54 100644 --- a/source/eventcore/drivers/select.d +++ b/source/eventcore/drivers/select.d @@ -24,6 +24,14 @@ version (Windows) { final class SelectEventDriver : PosixEventDriver { + override @property SelectEventDriver core() { return this; } + override @property SelectEventDriver files() { return this; } + override @property SelectEventDriver sockets() { return this; } + override @property SelectEventDriver udp() { return this; } + override @property SelectEventDriver events() { return this; } + override @property SelectEventDriver signals() { return this; } + override @property SelectEventDriver watchers() { return this; } + override bool doProcessEvents(Duration timeout) { //assert(Fiber.getThis() is null, "processEvents may not be called from within a fiber!");