X-Git-Url: https://git.llucax.com/software/druntime.git/blobdiff_plain/5a07183e26b7ca151959629420a83f59af5339f3..ee20c715e3f0be23c1732938dc222d436464c254:/src/gc/basic/gcx.d?ds=sidebyside diff --git a/src/gc/basic/gcx.d b/src/gc/basic/gcx.d index 0270dd5..b913c36 100644 --- a/src/gc/basic/gcx.d +++ b/src/gc/basic/gcx.d @@ -24,6 +24,8 @@ * Authors: Walter Bright, David Friedman, Sean Kelly */ +module gc.gcx; + // D Programming Language Garbage Collector implementation /************** Debugging ***************************/ @@ -50,10 +52,10 @@ private import gcbits; private import gcstats; private import gcalloc; -private import cstdlib = stdc.stdlib : calloc, free, malloc, realloc; -private import stdc.string; +private import cstdlib = core.stdc.stdlib : calloc, free, malloc, realloc; +private import core.stdc.string; -debug private import stdc.stdio; +debug private import core.stdc.stdio; version (GNU) { @@ -87,16 +89,13 @@ private extern (C) void rt_finalize( void* p, bool det = true ); - alias void delegate( void*, void* ) scanFn; - - extern (C) void rt_scanStaticData( scanFn scan ); - version (MULTI_THREADED) { extern (C) bool thread_needLock(); extern (C) void thread_suspendAll(); extern (C) void thread_resumeAll(); + alias void delegate( void*, void* ) scanFn; extern (C) void thread_scanAll( scanFn fn, void* curStackTop = null ); } @@ -261,7 +260,7 @@ class GC } - invariant + invariant() { if (gcx) { @@ -1164,6 +1163,22 @@ class GC } + /** + * + */ + int delegate(int delegate(inout void*)) rootIter() + { + if (!thread_needLock()) + { + return &gcx.rootIter; + } + else synchronized (gcLock) + { + return &gcx.rootIter; + } + } + + /** * add range to scan for roots */ @@ -1208,6 +1223,22 @@ class GC } + /** + * + */ + int delegate(int delegate(inout Range)) rangeIter() + { + if (!thread_needLock()) + { + return &gcx.rangeIter; + } + else synchronized (gcLock) + { + return &gcx.rangeIter; + } + } + + /** * do full garbage collection */ @@ -1437,7 +1468,7 @@ struct Gcx void initialize() { int dummy; - (cast(byte*)this)[0 .. Gcx.sizeof] = 0; + (cast(byte*)&this)[0 .. Gcx.sizeof] = 0; stackBottom = cast(char*)&dummy; log_init(); debug (THREADINVARIANT) @@ -1471,7 +1502,7 @@ struct Gcx void Invariant() { } - invariant + invariant() { if (inited) { @@ -1571,6 +1602,22 @@ struct Gcx } + /** + * + */ + int rootIter(int delegate(inout void*) dg) + { + int result = 0; + for( size_t i = 0; i < nroots; ++i ) + { + result = dg(roots[i]); + if (result) + break; + } + return result; + } + + /** * */ @@ -1624,6 +1671,22 @@ struct Gcx } + /** + * + */ + int rangeIter(int delegate(inout Range) dg) + { + int result = 0; + for( size_t i = 0; i < nranges; ++i ) + { + result = dg(ranges[i]); + if (result) + break; + } + return result; + } + + /** * Find Pool that pointer is in. * Return null if not in a Pool. @@ -2243,8 +2306,6 @@ struct Gcx pool.mark.copy(&pool.freebits); } - rt_scanStaticData( &mark ); - version (MULTI_THREADED) { if (!noStack) @@ -2807,7 +2868,7 @@ struct Pool void Invariant() { } - invariant + invariant() { //mark.Invariant(); //scan.Invariant();