* Authors: Walter Bright, David Friedman, Sean Kelly
*/
+module gc.gcx;
+
// D Programming Language Garbage Collector implementation
/************** Debugging ***************************/
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)
{
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 );
}
}
- invariant
+ invariant()
{
if (gcx)
{
}
+ /**
+ *
+ */
+ 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
*/
}
+ /**
+ *
+ */
+ int delegate(int delegate(inout Range)) rangeIter()
+ {
+ if (!thread_needLock())
+ {
+ return &gcx.rangeIter;
+ }
+ else synchronized (gcLock)
+ {
+ return &gcx.rangeIter;
+ }
+ }
+
+
/**
* do full garbage collection
*/
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)
void Invariant() { }
- invariant
+ invariant()
{
if (inited)
{
}
+ /**
+ *
+ */
+ 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;
+ }
+
+
/**
*
*/
}
+ /**
+ *
+ */
+ 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.
pool.mark.copy(&pool.freebits);
}
- rt_scanStaticData( &mark );
-
version (MULTI_THREADED)
{
if (!noStack)
void Invariant() { }
- invariant
+ invariant()
{
//mark.Invariant();
//scan.Invariant();