X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=includes%2Frts%2FOSThreads.h;h=ee59a5f62c6da1800c5708c87695f793225eb70c;hb=d52d50e40e06d7a74aa7725e7a1a89a0cf2d98a2;hp=2d32136379b0fc8ff7040f8d5b07208ead3a1da4;hpb=a2a67cd520b9841114d69a87a423dabcb3b4368e;p=ghc-hetmet.git diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h index 2d32136..ee59a5f 100644 --- a/includes/rts/OSThreads.h +++ b/includes/rts/OSThreads.h @@ -1,10 +1,15 @@ /* --------------------------------------------------------------------------- * - * (c) The GHC Team, 2001-2005 + * (c) The GHC Team, 2001-2009 * * Accessing OS threads functionality in a (mostly) OS-independent * manner. * + * Do not #include this file directly: #include "Rts.h" instead. + * + * To understand the structure of the RTS headers, see the wiki: + * http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes + * * --------------------------------------------------------------------------*/ #ifndef RTS_OSTHREADS_H @@ -48,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) { \ @@ -112,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. @@ -160,6 +174,7 @@ typedef void OSThreadProcAttr OSThreadProc(void *); extern int createOSThread ( OSThreadId* tid, OSThreadProc *startProc, void *param); extern rtsBool osThreadIsAlive ( OSThreadId id ); +extern void interruptOSThread (OSThreadId id); // // Condition Variables