Skip to content

Commit

Permalink
Added experimental Thread-Local GC
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Cimon committed Jun 17, 2015
1 parent 2ea784b commit 7da3939
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 123 deletions.
1 change: 1 addition & 0 deletions src/core/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ extern (C)

void _d_assert(string file, uint line)
{
asm { int 3; }
onAssertError(file, line);
}

Expand Down
16 changes: 11 additions & 5 deletions src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ private
//
extern (C) void rt_moduleTlsCtor();
extern (C) void rt_moduleTlsDtor();
extern (C) void initStaticDataGC();
extern (C) void gc_init_tls();
extern (C) void gc_term_tls();

}


Expand Down Expand Up @@ -141,6 +145,9 @@ version( Windows )
assert( obj.m_curr is &obj.m_main );
obj.m_main.bstack = getStackBottom();
obj.m_main.tstack = obj.m_main.bstack;

gc_init_tls();
initStaticDataGC();
obj.m_tlsgcdata = rt_tlsgc_init();

Thread.setThis( obj );
Expand Down Expand Up @@ -182,7 +189,7 @@ version( Windows )
rt_moduleTlsCtor();
obj.run();
rt_moduleTlsDtor();

gc_term_tls();
return 0;
}

Expand Down Expand Up @@ -243,6 +250,8 @@ else version( Posix )
assert( obj.m_curr is &obj.m_main );
obj.m_main.bstack = getStackBottom();
obj.m_main.tstack = obj.m_main.bstack;
gc_init_tls();
initStaticDataGC();
obj.m_tlsgcdata = rt_tlsgc_init();

atomicStore!(MemoryOrder.raw)(obj.m_isRunning, true);
Expand Down Expand Up @@ -319,7 +328,7 @@ else version( Posix )
obj.run();
rt_moduleTlsDtor();
version (Shared) cleanupLoadedLibraries();

gc_term_tls();
// NOTE: Normal cleanup is handled by scope(exit).

static if( __traits( compiles, pthread_cleanup ) )
Expand Down Expand Up @@ -1985,7 +1994,6 @@ extern (C) bool thread_isMainThread()
*/
extern (C) Thread thread_attachThis()
{
GC.disable(); scope(exit) GC.enable();

if (auto t = Thread.getThis())
return t;
Expand Down Expand Up @@ -2049,8 +2057,6 @@ version( Windows )
/// ditto
extern (C) Thread thread_attachByAddrB( Thread.ThreadAddr addr, void* bstack )
{
GC.disable(); scope(exit) GC.enable();

if (auto t = thread_findByAddr(addr))
return t;

Expand Down
Loading

0 comments on commit 7da3939

Please sign in to comment.