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.
This commit is contained in:
Sönke Ludwig 2016-10-05 13:15:04 +02:00
parent b1663cc472
commit 3868ee64ce
4 changed files with 41 additions and 9 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -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!();

View file

@ -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!");