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

Commit

Permalink
Merge pull request #247 from dawgfoto/GcxThreadCleanup
Browse files Browse the repository at this point in the history
Gcx thread cleanup
  • Loading branch information
complexmath committed Jun 22, 2012
2 parents cd9636e + b337a06 commit de4d3ef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 189 deletions.
63 changes: 15 additions & 48 deletions src/core/thread.d
Expand Up @@ -526,7 +526,7 @@ else version( Posix )
}
}

thread_callWithStackShell(&op);
callWithStackShell(&op);
}


Expand Down Expand Up @@ -2169,16 +2169,8 @@ extern (C) bool thread_needLock() nothrow
}


alias void delegate(void*) StackShellFn;

/**
* Calls the given delegate, passing the current thread's stack pointer
* to it.
*
* Params:
* fn = The function to call with the stack pointer.
*/
extern (C) void thread_callWithStackShell(scope StackShellFn fn)
// Calls the given delegate, passing the current thread's stack pointer to it.
private void callWithStackShell(scope void delegate(void* sp) fn)
in
{
assert(fn);
Expand Down Expand Up @@ -2603,28 +2595,23 @@ enum ScanType
alias void delegate(void*, void*) ScanAllThreadsFn;
alias void delegate(ScanType, void*, void*) ScanAllThreadsTypeFn;

/**
* The main entry point for garbage collection. The supplied delegate
* will be passed ranges representing both stack and register values.
*
* Params:
* scan = The scanner function. It should scan from p1 through p2 - 1.
* curStackTop = An optional pointer to the top of the calling thread's stack.
*
* In:
* This routine must be preceded by a call to thread_suspendAll.
*/
extern (C) void thread_scanAllType( scope ScanAllThreadsTypeFn scan, void* curStackTop = null )
extern (C) void thread_scanAllType( scope ScanAllThreadsTypeFn scan )
in
{
assert( suspendDepth > 0 );
}
body
{
callWithStackShell(sp => scanAllTypeImpl(scan, sp));
}


private void scanAllTypeImpl( scope ScanAllThreadsTypeFn scan, void* curStackTop )
{
Thread thisThread = null;
void* oldStackTop = null;

if( curStackTop && Thread.sm_tbeg )
if( Thread.sm_tbeg )
{
thisThread = Thread.getThis();
if( !thisThread.m_lock )
Expand All @@ -2636,7 +2623,7 @@ body

scope( exit )
{
if( curStackTop && Thread.sm_tbeg )
if( Thread.sm_tbeg )
{
if( !thisThread.m_lock )
{
Expand Down Expand Up @@ -2680,30 +2667,10 @@ body
}
}

/**
* The main entry point for garbage collection. The supplied delegate
* will be passed ranges representing both stack and register values.
*
* Params:
* scan = The scanner function. It should scan from p1 through p2 - 1.
* curStackTop = An optional pointer to the top of the calling thread's stack.
*
* In:
* This routine must be preceded by a call to thread_suspendAll.
*/
extern (C) void thread_scanAll( scope ScanAllThreadsFn scan, void* curStackTop = null )
in
{
assert( suspendDepth > 0 );
}
body
{
void op( ScanType type, void* p1, void* p2 )
{
scan(p1, p2);
}

thread_scanAllType(&op, curStackTop);
extern (C) void thread_scanAll( scope ScanAllThreadsFn scan )
{
thread_scanAllType((type, p1, p2) => scan(p1, p2));
}

/**
Expand Down
18 changes: 2 additions & 16 deletions src/core/thread.di
Expand Up @@ -551,18 +551,6 @@ shared static ~this();
extern (C) bool thread_needLock() nothrow;


alias void delegate(void*) StackShellFn;

/**
* Calls the given delegate, passing the current thread's stack pointer
* to it.
*
* Params:
* fn = The function to call with the stack pointer.
*/
extern (C) void thread_callWithStackShell(scope StackShellFn fn);


/**
* Suspend all threads but the calling thread for "stop the world" garbage
* collection runs. This function may be called multiple times, and must
Expand Down Expand Up @@ -604,12 +592,11 @@ alias void delegate(ScanType, void*, void*) ScanAllThreadsTypeFn;
*
* Params:
* scan = The scanner function. It should scan from p1 through p2 - 1.
* curStackTop = An optional pointer to the top of the calling thread's stack.
*
* In:
* This routine must be preceded by a call to thread_suspendAll.
*/
extern (C) void thread_scanAllType( scope ScanAllThreadsTypeFn scan, void* curStackTop = null );
extern (C) void thread_scanAllType( scope ScanAllThreadsTypeFn scan );


/**
Expand All @@ -618,12 +605,11 @@ extern (C) void thread_scanAllType( scope ScanAllThreadsTypeFn scan, void* curSt
*
* Params:
* scan = The scanner function. It should scan from p1 through p2 - 1.
* curStackTop = An optional pointer to the top of the calling thread's stack.
*
* In:
* This routine must be preceded by a call to thread_suspendAll.
*/
extern (C) void thread_scanAll( scope ScanAllThreadsFn scan, void* curStackTop = null );
extern (C) void thread_scanAll( scope ScanAllThreadsFn scan );

enum IsMarked : int
{
Expand Down

0 comments on commit de4d3ef

Please sign in to comment.