X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Frts%2FOSThreads.h;h=0ba6fb99576149d9fc7488f4313faa064ce77b1b;hb=d4a2fe2b1578d162fa2880f760cfcfd547973039;hp=571c90ea6de088141dc66e5f2d77559ef92e88b9;hpb=287681a847f1df6b0eff513f68763e6628380317;p=ghc-hetmet.git diff --git a/ghc/rts/OSThreads.h b/ghc/rts/OSThreads.h index 571c90e..0ba6fb9 100644 --- a/ghc/rts/OSThreads.h +++ b/ghc/rts/OSThreads.h @@ -21,8 +21,8 @@ typedef pthread_t OSThreadId; #define INIT_COND_VAR PTHREAD_COND_INITIALIZER #ifdef LOCK_DEBUG -#define ACQUIRE_LOCK(mutex) fprintf(stderr, "ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); fflush(stderr); pthread_mutex_lock(mutex) -#define RELEASE_LOCK(mutex) fprintf(stderr, "RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); fflush(stderr); pthread_mutex_unlock(mutex) +#define ACQUIRE_LOCK(mutex) debugBelch("ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); pthread_mutex_lock(mutex) +#define RELEASE_LOCK(mutex) debugBelch("RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); pthread_mutex_unlock(mutex) #else #define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex) #define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex) @@ -31,6 +31,8 @@ typedef pthread_t OSThreadId; # elif defined(HAVE_WINDOWS_H) #include +#include "RtsUtils.h" + typedef HANDLE Condition; typedef HANDLE Mutex; typedef DWORD OSThreadId; @@ -38,8 +40,22 @@ typedef DWORD OSThreadId; #define INIT_MUTEX_VAR 0 #define INIT_COND_VAR 0 -#define ACQUIRE_LOCK(mutex) WaitForSingleObject(mutex,INFINITE) -#define RELEASE_LOCK(mutex) ReleaseMutex(mutex) +static inline void +ACQUIRE_LOCK(Mutex *mutex) +{ + if (WaitForSingleObject(*mutex,INFINITE) == WAIT_FAILED) { + barf("WaitForSingleObject: %d", GetLastError()); + } +} + +static inline void +RELEASE_LOCK(Mutex *mutex) +{ + if (ReleaseMutex(*mutex) == 0) { + barf("ReleaseMutex: %d", GetLastError()); + } +} + # else # error "Threads not supported" # endif