Merge pull request #79 from vibe-d/nested_initialization
Fix initialization behavior when being loaded as a shared library.
This commit is contained in:
commit
745e4ea2c6
|
@ -27,25 +27,36 @@ else alias NativeEventDriver = EventDriver;
|
|||
static if (!is(NativeEventDriver == EventDriver)) {
|
||||
static this()
|
||||
{
|
||||
if (!s_driver) s_driver = new NativeEventDriver;
|
||||
if (!s_isMainThread) {
|
||||
if (!s_initCount++) {
|
||||
assert(s_driver is null);
|
||||
s_driver = new NativeEventDriver;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ~this()
|
||||
{
|
||||
if (!s_isMainThread)
|
||||
if (!s_isMainThread) {
|
||||
if (!--s_initCount)
|
||||
s_driver.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
shared static this()
|
||||
{
|
||||
if (!s_initCount++) {
|
||||
s_driver = new NativeEventDriver;
|
||||
s_isMainThread = true;
|
||||
}
|
||||
}
|
||||
|
||||
shared static ~this()
|
||||
{
|
||||
if (!--s_initCount) {
|
||||
s_driver.dispose();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
void setupEventDriver(EventDriver driver)
|
||||
{
|
||||
|
@ -58,4 +69,7 @@ static if (!is(NativeEventDriver == EventDriver)) {
|
|||
private {
|
||||
NativeEventDriver s_driver;
|
||||
bool s_isMainThread;
|
||||
// keeps track of nested DRuntime initializations that happen when
|
||||
// (un)loading shared libaries.
|
||||
int s_initCount = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue