X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=includes%2Frts%2FOSThreads.h;h=c70f418229a8f79ce814fdc855fa89176ea3e068;hb=HEAD;hp=5d3e6ba1406df1c06e12e64da73b762a01af4878;hpb=83d563cb9ede0ba792836e529b1e2929db926355;p=ghc-hetmet.git diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h index 5d3e6ba..c70f418 100644 --- a/includes/rts/OSThreads.h +++ b/includes/rts/OSThreads.h @@ -17,7 +17,7 @@ #if defined(THREADED_RTS) /* to the end */ -# if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS) +#if defined(HAVE_PTHREAD_H) && !defined(mingw32_HOST_OS) #if CMINUSMINUS @@ -53,6 +53,14 @@ typedef pthread_key_t ThreadLocalKey; barf("multiple ACQUIRE_LOCK: %s %d", __FILE__,__LINE__); \ } +// Returns zero if the lock was acquired. +EXTERN_INLINE int TRY_ACQUIRE_LOCK(pthread_mutex_t *mutex); +EXTERN_INLINE int TRY_ACQUIRE_LOCK(pthread_mutex_t *mutex) +{ + LOCK_DEBUG_BELCH("TRY_ACQUIRE_LOCK", mutex); + return pthread_mutex_trylock(mutex); +} + #define RELEASE_LOCK(mutex) \ LOCK_DEBUG_BELCH("RELEASE_LOCK", mutex); \ if (pthread_mutex_unlock(mutex) != 0) { \ @@ -117,8 +125,9 @@ typedef CRITICAL_SECTION Mutex; #else -#define ACQUIRE_LOCK(mutex) EnterCriticalSection(mutex) -#define RELEASE_LOCK(mutex) LeaveCriticalSection(mutex) +#define ACQUIRE_LOCK(mutex) EnterCriticalSection(mutex) +#define TRY_ACQUIRE_LOCK(mutex) (TryEnterCriticalSection(mutex) == 0) +#define RELEASE_LOCK(mutex) LeaveCriticalSection(mutex) // I don't know how to do this. TryEnterCriticalSection() doesn't do // the right thing.