X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FOSThreads.h;h=a65e002b3c4b0b58fd8b66ccf21d0f4e8a2c6954;hb=a80264a591226e4ba7037ab30cb2812ccdf8f686;hp=eb5d9e792524436e9eb0d232960091379f18f46e;hpb=05abfa38be95d3042b09738408ba95beac50418d;p=ghc-hetmet.git diff --git a/ghc/rts/OSThreads.h b/ghc/rts/OSThreads.h index eb5d9e7..a65e002 100644 --- a/ghc/rts/OSThreads.h +++ b/ghc/rts/OSThreads.h @@ -20,12 +20,19 @@ typedef pthread_t OSThreadId; #define INIT_MUTEX_VAR PTHREAD_MUTEX_INITIALIZER #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) +#else #define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex) #define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex) +#endif # elif defined(HAVE_WINDOWS_H) #include +#include "RtsUtils.h" + typedef HANDLE Condition; typedef HANDLE Mutex; typedef DWORD OSThreadId; @@ -33,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