-
Notifications
You must be signed in to change notification settings - Fork 2
/
gc_hook.d
40 lines (34 loc) · 1.46 KB
/
gc_hook.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// License: Boost
module sidero.base.allocators.gc_hook;
import sidero.base.allocators.gc;
version(D_BetterC) {
} else {
import core.memory : GC;
import core.runtime : rt_init, rt_term;
version(Windows) {
// We handles Windows support as part of DllMain
} else {
version(InitAfterDruntimeSideroBase) {
// Unfortunately there are some cases where we need druntime to initialize before us
// for example if are building for unittesting.
shared static this() {
// adding this extra lock, guarantees we control when the druntime goes away
rt_init;
registerGC(&GC.malloc, &GC.enable, &GC.disable, &GC.collect, &GC.minimize, &GC.addRange,
&GC.removeRange, &GC.runFinalizers, &GC.inFinalizer);
}
} else {
pragma(crt_constructor) extern (C) void register_sidero_gc_register() {
// adding this extra lock, guarantees we control when the druntime goes away
rt_init;
registerGC(&GC.malloc, &GC.enable, &GC.disable, &GC.collect, &GC.minimize, &GC.addRange,
&GC.removeRange, &GC.runFinalizers, &GC.inFinalizer);
}
}
pragma(crt_destructor) extern (C) void register_sidero_gc_deregister() {
// we really really want our stuff to deregister before druntime does
deregisterGC(&GC.malloc);
rt_term;
}
}
}