Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
replace global per-GC instance pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Jun 27, 2016
1 parent c8cba0f commit e342ac4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/gc/impl/conservative/gc.d
Expand Up @@ -249,8 +249,6 @@ debug (LOGGING)

/* ============================ GC =============================== */

__gshared ConservativeGC instance;

class ConservativeGC : GC
{
// For passing to debug code (not thread safe)
Expand Down Expand Up @@ -286,7 +284,7 @@ class ConservativeGC : GC

auto init = typeid(ConservativeGC).initializer();
assert(init.length == __traits(classInstanceSize, ConservativeGC));
instance = cast(ConservativeGC) memcpy(p, init.ptr, init.length);
auto instance = cast(ConservativeGC) memcpy(p, init.ptr, init.length);
instance.__ctor();

gc = instance;
Expand Down
17 changes: 8 additions & 9 deletions src/gc/impl/manual/gc.d
Expand Up @@ -35,8 +35,6 @@ import cstdlib = core.stdc.stdlib : calloc, free, malloc, realloc;

extern (C) void onOutOfMemoryError(void* pretend_sideffect = null) @trusted pure nothrow @nogc; /* dmd @@@BUG11461@@@ */

__gshared ManualGC instance;

class ManualGC : GC
{
__gshared Array!Root roots;
Expand All @@ -55,19 +53,20 @@ class ManualGC : GC

auto init = typeid(ManualGC).initializer();
assert(init.length == __traits(classInstanceSize, ManualGC));
instance = cast(ManualGC) memcpy(p, init.ptr, init.length);
auto instance = cast(ManualGC) memcpy(p, init.ptr, init.length);
instance.__ctor();

gc = instance;
}

static void finalize()
static void finalize(ref GC gc)
{
if (instance !is null)
{
instance.Dtor();
cstdlib.free(cast(void*) instance);
}
if (config.gc != "manual")
return;

auto instance = cast(ManualGC) gc;
instance.Dtor();
cstdlib.free(cast(void*) instance);
}

this()
Expand Down
4 changes: 2 additions & 2 deletions src/gc/proxy.d
Expand Up @@ -67,8 +67,8 @@ extern (C)

thread_term();

ManualGC.finalize();
ConservativeGC.finalize();
ManualGC.finalize(initialGC);
ConservativeGC.finalize(initialGC);
}

void gc_enable()
Expand Down

0 comments on commit e342ac4

Please sign in to comment.