From 304de7a39af606276139b4fb6d6a9a5b75f2b303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 9 Apr 2019 18:15:39 +0200 Subject: [PATCH 1/2] Use Mallocator for Win32 file system watcher buffer. Avoids allocating using the GC, which `theAllocator` points to by default. --- source/eventcore/drivers/winapi/watchers.d | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/eventcore/drivers/winapi/watchers.d b/source/eventcore/drivers/winapi/watchers.d index fb89444..537d6f5 100644 --- a/source/eventcore/drivers/winapi/watchers.d +++ b/source/eventcore/drivers/winapi/watchers.d @@ -6,7 +6,8 @@ import eventcore.driver; import eventcore.drivers.winapi.core; import eventcore.drivers.winapi.driver : WinAPIEventDriver; // FIXME: this is an ugly dependency import eventcore.internal.win32; -import std.experimental.allocator : dispose, makeArray, theAllocator; +import std.experimental.allocator.mallocator : Mallocator; +import std.experimental.allocator : dispose, makeArray; final class WinAPIEventDriverWatchers : EventDriverWatchers { @@ -23,6 +24,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { override WatcherID watchDirectory(string path, bool recursive, FileChangesCallback callback) { import std.utf : toUTF16z; + auto handle = () @trusted { scope (failure) assert(false); return CreateFileW(path.toUTF16z, FILE_LIST_DIRECTORY, @@ -43,7 +45,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { slot.callback = callback; slot.overlapped.driver = m_core; slot.buffer = () @trusted { - try return theAllocator.makeArray!ubyte(16384); + try return Mallocator.instance.makeArray!ubyte(16384); catch (Exception e) assert(false, "Failed to allocate directory watcher buffer."); } (); if (!triggerRead(handle, *slot)) { @@ -83,7 +85,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { CloseHandle(handle); () @trusted { - try theAllocator.dispose(slot.watcher.buffer); + try Mallocator.instance.dispose(slot.watcher.buffer); catch (Exception e) assert(false, "Freeing directory watcher buffer failed."); } (); slot.watcher.buffer = null; From 9feccbe537a901f4e49111f175c621c7ffc87b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 13 Apr 2019 17:25:47 +0200 Subject: [PATCH 2/2] Fix missing nogc annotations for userData accessors. User data only compiled successfully for sockets before this change. --- source/eventcore/driver.d | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/source/eventcore/driver.d b/source/eventcore/driver.d index c501341..e5e13a0 100644 --- a/source/eventcore/driver.d +++ b/source/eventcore/driver.d @@ -466,8 +466,8 @@ interface EventDriverFiles { @property final ref T userData(T)(FileFD descriptor) @trusted { import std.conv : emplace; - static void init(void* ptr) { emplace(cast(T*)ptr); } - static void destr(void* ptr) { destroy(*cast(T*)ptr); } + static void init(void* ptr) @nogc { emplace(cast(T*)ptr); } + static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); } return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr); } @@ -524,8 +524,8 @@ interface EventDriverEvents { @property final ref T userData(T)(EventID descriptor) @trusted { import std.conv : emplace; - static void init(void* ptr) { emplace(cast(T*)ptr); } - static void destr(void* ptr) { destroy(*cast(T*)ptr); } + static void init(void* ptr) @nogc { emplace(cast(T*)ptr); } + static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); } return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr); } @@ -610,8 +610,8 @@ interface EventDriverTimers { @property final ref T userData(T)(TimerID descriptor) @trusted { import std.conv : emplace; - static void init(void* ptr) { emplace(cast(T*)ptr); } - static void destr(void* ptr) { destroy(*cast(T*)ptr); } + static void init(void* ptr) @nogc { emplace(cast(T*)ptr); } + static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); } return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr); } @@ -643,8 +643,8 @@ interface EventDriverWatchers { @property final ref T userData(T)(WatcherID descriptor) @trusted { import std.conv : emplace; - static void init(void* ptr) { emplace(cast(T*)ptr); } - static void destr(void* ptr) { destroy(*cast(T*)ptr); } + static void init(void* ptr) @nogc { emplace(cast(T*)ptr); } + static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); } return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr); } @@ -716,8 +716,8 @@ interface EventDriverProcesses { @property final ref T userData(T)(ProcessID descriptor) @trusted { import std.conv : emplace; - static void init(void* ptr) { emplace(cast(T*)ptr); } - static void destr(void* ptr) { destroy(*cast(T*)ptr); } + static void init(void* ptr) @nogc { emplace(cast(T*)ptr); } + static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); } return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr); } @@ -791,8 +791,8 @@ interface EventDriverPipes { @property final ref T userData(T)(PipeFD descriptor) @trusted { import std.conv : emplace; - static void init(void* ptr) { emplace(cast(T*)ptr); } - static void destr(void* ptr) { destroy(*cast(T*)ptr); } + static void init(void* ptr) @nogc { emplace(cast(T*)ptr); } + static void destr(void* ptr) @nogc { destroy(*cast(T*)ptr); } return *cast(T*)rawUserData(descriptor, T.sizeof, &init, &destr); }