From 29aee9ee5219bf59d5d61aed76ea6b64c2456576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 25 Nov 2017 16:59:53 +0100 Subject: [PATCH] Defer driver dispose in main thread to shared static ~this. Allows dependent code to still access the driver from within their shared static ~this. vibe-core notably falls into this category. --- source/eventcore/core.d | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/eventcore/core.d b/source/eventcore/core.d index 547d515..9889513 100644 --- a/source/eventcore/core.d +++ b/source/eventcore/core.d @@ -32,12 +32,19 @@ static if (!is(NativeEventDriver == EventDriver)) { static ~this() { - s_driver.dispose(); + if (!s_isMainThread) + s_driver.dispose(); } shared static this() { s_driver = new NativeEventDriver; + s_isMainThread = true; + } + + shared static ~this() + { + s_driver.dispose(); } } else { void setupEventDriver(EventDriver driver) @@ -48,4 +55,7 @@ static if (!is(NativeEventDriver == EventDriver)) { } } -private NativeEventDriver s_driver; +private { + NativeEventDriver s_driver; + bool s_isMainThread; +}