// NOTE: No GC allocations may occur until the stack pointers have
// been set and Thread.getThis returns a valid reference to
// this thread object (this latter condition is not strictly
- // necessary on Win32 but it should be followed for the sake
- // of consistency).
+ // necessary on Windows but it should be followed for the
+ // sake of consistency).
// TODO: Consider putting an auto exception object here (using
// alloca) forOutOfMemoryError plus something to track
// NOTE: No GC allocations may occur until the stack pointers have
// been set and Thread.getThis returns a valid reference to
// this thread object (this latter condition is not strictly
- // necessary on Win32 but it should be followed for the sake
- // of consistency).
+ // necessary on Windows but it should be followed for the
+ // sake of consistency).
// TODO: Consider putting an auto exception object here (using
// alloca) forOutOfMemoryError plus something to track
return;
}
- version( Win32 )
+ version( Windows )
{
m_addr = m_addr.init;
CloseHandle( m_hndl );
}
body
{
- version( Win32 ) {} else
+ version( Windows ) {} else
version( Posix )
{
pthread_attr_t attr;
// and causing memory to be collected that is still in use.
synchronized( slock )
{
- version( Win32 )
+ version( Windows )
{
m_hndl = cast(HANDLE) _beginthreadex( null, m_sz, &thread_entryPoint, cast(void*) this, 0, &m_addr );
if( cast(size_t) m_hndl == 0 )
*/
final Object join( bool rethrow = true )
{
- version( Win32 )
+ version( Windows )
{
if( WaitForSingleObject( m_hndl, INFINITE ) != WAIT_OBJECT_0 )
throw new ThreadException( "Unable to join thread" );
return false;
}
- version( Win32 )
+ version( Windows )
{
uint ecode = 0;
GetExitCodeThread( m_hndl, &ecode );
*/
final int priority()
{
- version( Win32 )
+ version( Windows )
{
return GetThreadPriority( m_hndl );
}
*/
final void priority( int val )
{
- version( Win32 )
+ version( Windows )
{
if( !SetThreadPriority( m_hndl, val ) )
throw new ThreadException( "Unable to set thread priority" );
* Example:
* ------------------------------------------------------------------------
*
- * Thread.sleep( 500 ); // sleep for 50 milliseconds
+ * Thread.sleep( 500_000 ); // sleep for 50 milliseconds
* Thread.sleep( 50_000_000 ); // sleep for 5 seconds
*
* ------------------------------------------------------------------------
}
body
{
- version( Win32 )
+ version( Windows )
{
enum : uint
{
MAX_SLEEP_MILLIS = uint.max - 1
}
- period = period < TICKS_PER_MILLI ?
- 1 :
- period / TICKS_PER_MILLI;
+ // NOTE: In instances where all other threads in the process have a
+ // lower priority than the current thread, the current thread
+ // will not yield with a sleep time of zero. However, unlike
+ // yield(), the user is not asking for a yield to occur but
+ // only for execution to suspend for the requested interval.
+ // Therefore, expected performance may not be met if a yield
+ // is forced upon the user.
+ period /= TICKS_PER_MILLI;
while( period > MAX_SLEEP_MILLIS )
{
Sleep( MAX_SLEEP_MILLIS );
*/
static void yield()
{
- version( Win32 )
+ version( Windows )
{
// NOTE: Sleep(1) is necessary because Sleep(0) does not give
// lower priority threads any timeslice, so looping on
// NOTE: This function may not be called until thread_init has
// completed. See thread_suspendAll for more information
// on why this might occur.
- version( Win32 )
+ version( Windows )
{
return cast(Thread) TlsGetValue( sm_this );
}
*/
static this()
{
- version( Win32 )
+ version( Windows )
{
PRIORITY_MIN = -15;
PRIORITY_MAX = 15;
//
// Standard types
//
- version( Win32 )
+ version( Windows )
{
alias uint TLSKey;
alias uint ThreadAddr;
//
// Standard thread data
//
- version( Win32 )
+ version( Windows )
{
HANDLE m_hndl;
}
//
static void setThis( Thread t )
{
- version( Win32 )
+ version( Windows )
{
TlsSetValue( sm_this, cast(void*) t );
}
Context* m_curr;
bool m_lock;
- version( Win32 )
+ version( Windows )
{
uint[8] m_reg; // edi,esi,ebp,esp,ebx,edx,ecx,eax
}
{
assert( t );
assert( t.next || t.prev );
- version( Win32 )
+ version( Windows )
{
// NOTE: This doesn't work for Posix as m_isRunning must be set to
// false after the thread is removed during normal execution.
// exist to be scanned at this point, it is sufficient for these
// functions to detect the condition and return immediately.
- version( Win32 )
+ version( Windows )
{
Thread.sm_this = TlsAlloc();
assert( Thread.sm_this != TLS_OUT_OF_INDEXES );
*/
extern (C) void thread_attachThis()
{
- version( Win32 )
+ version( Windows )
{
Thread thisThread = new Thread();
Thread.Context* thisContext = &thisThread.m_main;
*/
void suspend( Thread t )
{
- version( Win32 )
+ version( Windows )
{
if( t.m_addr != GetCurrentThreadId() && SuspendThread( t.m_hndl ) == 0xFFFFFFFF )
{
*/
void resume( Thread t )
{
- version( Win32 )
+ version( Windows )
{
if( t.m_addr != GetCurrentThreadId() && ResumeThread( t.m_hndl ) == 0xFFFFFFFF )
{
scan( c.bstack, c.tstack + 1 );
}
}
- version( Win32 )
+ version( Windows )
{
for( Thread t = Thread.sm_tbeg; t; t = t.next )
{
}
else
{
- version( Win32 )
+ version( Windows )
version = AsmX86_Win32;
else version( Posix )
version = AsmX86_Posix;
*/
static Fiber getThis()
{
- version( Win32 )
+ version( Windows )
{
return cast(Fiber) TlsGetValue( sm_this );
}
static this()
{
- version( Win32 )
+ version( Windows )
{
sm_this = TlsAlloc();
assert( sm_this != TLS_OUT_OF_INDEXES );
//
static void setThis( Fiber f )
{
- version( Win32 )
+ version( Windows )
{
TlsSetValue( sm_this, cast(void*) f );
}