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.
This commit is contained in:
Sönke Ludwig 2017-11-25 16:59:53 +01:00
parent 2d4ccf454d
commit 29aee9ee52

View file

@ -32,12 +32,19 @@ static if (!is(NativeEventDriver == EventDriver)) {
static ~this() static ~this()
{ {
if (!s_isMainThread)
s_driver.dispose(); s_driver.dispose();
} }
shared static this() shared static this()
{ {
s_driver = new NativeEventDriver; s_driver = new NativeEventDriver;
s_isMainThread = true;
}
shared static ~this()
{
s_driver.dispose();
} }
} else { } else {
void setupEventDriver(EventDriver driver) void setupEventDriver(EventDriver driver)
@ -48,4 +55,7 @@ static if (!is(NativeEventDriver == EventDriver)) {
} }
} }
private NativeEventDriver s_driver; private {
NativeEventDriver s_driver;
bool s_isMainThread;
}