diff --git a/src/core/thread.d b/src/core/thread.d index f4847d1b05..3fd6461121 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -998,30 +998,7 @@ class Thread // NOTE: This function may not be called until thread_init has // completed. See thread_suspendAll for more information // on why this might occur. - version( Windows ) - { - auto t = cast(Thread) TlsGetValue( sm_this ); - - // NOTE: If this thread was attached via thread_attachByAddr then - // this TLS lookup won't initially be set, so when the TLS - // lookup fails, try an exhaustive search. - if( t is null ) - { - t = thread_findByAddr( GetCurrentThreadId() ); - setThis( t ); - } - return t; - } - else version( Posix ) - { - auto t = cast(Thread) pthread_getspecific( sm_this ); - - // NOTE: See the comment near thread_findByAddr() for why the - // secondary thread_findByAddr lookup can't be done on - // Posix. However, because thread_attachByAddr() is for - // Windows only, the secondary lookup is pointless anyway. - return t; - } + return sm_this; } @@ -1177,7 +1154,7 @@ private: // // Local storage // - __gshared TLSKey sm_this; + static Thread sm_this; // @@ -1226,14 +1203,7 @@ private: // static void setThis( Thread t ) { - version( Windows ) - { - TlsSetValue( sm_this, cast(void*) t ); - } - else version( Posix ) - { - pthread_setspecific( sm_this, cast(void*) t ); - } + sm_this = t; } @@ -1658,17 +1628,8 @@ extern (C) void thread_init() // exist to be scanned at this point, it is sufficient for these // functions to detect the condition and return immediately. - version( Windows ) - { - Thread.sm_this = TlsAlloc(); - assert( Thread.sm_this != TLS_OUT_OF_INDEXES ); - } - else version( OSX ) + version( OSX ) { - int status; - - status = pthread_key_create( &Thread.sm_this, null ); - assert( status == 0 ); } else version( Posix ) { @@ -1712,9 +1673,6 @@ extern (C) void thread_init() status = sem_init( &suspendCount, 0, 0 ); assert( status == 0 ); - - status = pthread_key_create( &Thread.sm_this, null ); - assert( status == 0 ); } Thread.sm_main = thread_attachThis(); } @@ -1823,7 +1781,11 @@ version( Windows ) else { thisThread.m_hndl = OpenThreadHandle( addr ); - impersonate_thread(addr, { thisThread.m_tlsgcdata = rt.tlsgc.init(); }); + impersonate_thread(addr, + { + thisThread.m_tlsgcdata = rt.tlsgc.init(); + Thread.setThis( thisThread ); + }); } Thread.add( thisThread );