X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fwin32%2FOSThreads.c;h=ed5c968cf1cfd6a609a16e3693680e769a9b1603;hb=842e9d6628a27cf1f420d53f6a5901935dc50c54;hp=c772be38f4ed3e7b6400280153ff9f4dbcc56473;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c index c772be3..ed5c968 100644 --- a/rts/win32/OSThreads.c +++ b/rts/win32/OSThreads.c @@ -7,10 +7,13 @@ * * --------------------------------------------------------------------------*/ +#define _WIN32_WINNT 0x0500 + #include "Rts.h" #if defined(THREADED_RTS) #include "OSThreads.h" #include "RtsUtils.h" +#include /* For reasons not yet clear, the entire contents of process.h is protected * by __STRICT_ANSI__ not being defined. @@ -38,7 +41,8 @@ initCondition( Condition* pCond ) NULL); /* unnamed => process-local. */ if ( h == NULL ) { - errorBelch("initCondition: unable to create"); + sysErrorBelch("initCondition: unable to create"); + stg_exit(EXIT_FAILURE); } *pCond = h; return; @@ -48,7 +52,7 @@ void closeCondition( Condition* pCond ) { if ( CloseHandle(*pCond) == 0 ) { - errorBelch("closeCondition: failed to close"); + sysErrorBelch("closeCondition: failed to close"); } return; } @@ -64,7 +68,8 @@ rtsBool signalCondition ( Condition* pCond ) { if (SetEvent(*pCond) == 0) { - barf("SetEvent: %d", GetLastError()); + sysErrorBelch("SetEvent"); + stg_exit(EXIT_FAILURE); } return rtsTrue; } @@ -110,12 +115,33 @@ osThreadId() return GetCurrentThreadId(); } +rtsBool +osThreadIsAlive(OSThreadId id) +{ + DWORD exit_code; + HANDLE hdl; + if (!(hdl = OpenThread(THREAD_QUERY_INFORMATION,FALSE,id))) { + sysErrorBelch("osThreadIsAlive: OpenThread"); + stg_exit(EXIT_FAILURE); + } + if (!GetExitCodeThread(hdl, &exit_code)) { + sysErrorBelch("osThreadIsAlive: GetExitCodeThread"); + stg_exit(EXIT_FAILURE); + } + return (exit_code == STILL_ACTIVE); +} + #ifdef USE_CRITICAL_SECTIONS void initMutex (Mutex* pMut) { InitializeCriticalSectionAndSpinCount(pMut,4000); } +void +closeMutex (Mutex* pMut) +{ + DeleteCriticalSection(pMut); +} #else void initMutex (Mutex* pMut) @@ -127,6 +153,11 @@ initMutex (Mutex* pMut) *pMut = h; return; } +void +closeMutex (Mutex* pMut) +{ + CloseHandle(*pMut); +} #endif void @@ -149,7 +180,8 @@ getThreadLocalVar (ThreadLocalKey *key) // r is allowed to be NULL - it can mean that either there was an // error or the stored value is in fact NULL. if (GetLastError() != NO_ERROR) { - barf("getThreadLocalVar: key not found"); + sysErrorBelch("getThreadLocalVar"); + stg_exit(EXIT_FAILURE); } #endif return r; @@ -161,7 +193,19 @@ setThreadLocalVar (ThreadLocalKey *key, void *value) BOOL b; b = TlsSetValue(*key, value); if (!b) { - barf("setThreadLocalVar: %d", GetLastError()); + sysErrorBelch("setThreadLocalVar"); + stg_exit(EXIT_FAILURE); + } +} + +void +freeThreadLocalKey (ThreadLocalKey *key) +{ + BOOL r; + r = TlsFree(*key); + if (r == 0) { + DWORD dw = GetLastError(); + barf("freeThreadLocalKey failed: %lu", dw); } }