X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Frts%2FOSThreads.h;h=0ba6fb99576149d9fc7488f4313faa064ce77b1b;hb=52d87e8b21e6df632ce56780d32011b7f9244ee4;hp=8cc06c22e780739ba0dd0ee316ad9d5caab9f9bb;hpb=3b9c5eb29bbb47a5733e37c9940789342d9d6f49;p=ghc-hetmet.git diff --git a/ghc/rts/OSThreads.h b/ghc/rts/OSThreads.h index 8cc06c2..0ba6fb9 100644 --- a/ghc/rts/OSThreads.h +++ b/ghc/rts/OSThreads.h @@ -9,39 +9,75 @@ * --------------------------------------------------------------------------*/ #ifndef __OSTHREADS_H__ #define __OSTHREADS_H__ -#if defined(RTS_SUPPORTS_THREADS) /*to the end */ +#if defined(RTS_SUPPORTS_THREADS) /* to the end */ -#if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS) -#include -typedef pthread_cond_t CondVar; -typedef pthread_mutex_t MutexVar; +# if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS) +# include +typedef pthread_cond_t Condition; +typedef pthread_mutex_t Mutex; typedef pthread_t OSThreadId; -#define INIT_MUTEX_VAR PTHREAD_MUTEX_INITIALIZER -#define INIT_COND_VAR PTHREAD_COND_INITIALIZER -#elif defined(HAVE_WINDOWS_H) +#define INIT_MUTEX_VAR PTHREAD_MUTEX_INITIALIZER +#define INIT_COND_VAR PTHREAD_COND_INITIALIZER + +#ifdef LOCK_DEBUG +#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) +#endif + +# elif defined(HAVE_WINDOWS_H) #include -typedef HANDLE CondVar; -typedef HANDLE MutexVar; -typedef HANDLE OSThreadId; + +#include "RtsUtils.h" + +typedef HANDLE Condition; +typedef HANDLE Mutex; +typedef DWORD OSThreadId; #define INIT_MUTEX_VAR 0 #define INIT_COND_VAR 0 -#else -#error "Threads not supported" -#endif -extern void initCondVar ( CondVar* pCond ); -extern void closeCondVar ( CondVar* pCond ); -extern rtsBool broadcastCondVar (CondVar* pCond ); -extern rtsBool signalCondVar ( CondVar* pCond ); -extern rtsBool waitCondVar ( CondVar* pCond, MutexVar* pMut); +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 -extern OSThreadId osThreadId(void); -extern void shutdownThread(void); -extern int createOSThread ( OSThreadId* tid, void *(*startProc)(void*)); +extern void initCondition ( Condition* pCond ); +extern void closeCondition ( Condition* pCond ); +extern rtsBool broadcastCondition ( Condition* pCond ); +extern rtsBool signalCondition ( Condition* pCond ); +extern rtsBool waitCondition ( Condition* pCond, + Mutex* pMut ); + +extern void initMutex ( Mutex* pMut ); + +extern OSThreadId osThreadId ( void ); +extern void shutdownThread ( void ); +extern void yieldThread ( void ); +extern int createOSThread ( OSThreadId* tid, + void (*startProc)(void) ); +#else -extern void initMutexVar ( MutexVar* pMut ); +#define ACQUIRE_LOCK(l) +#define RELEASE_LOCK(l) #endif /* defined(RTS_SUPPORTS_THREADS) */