X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=includes%2FOSThreads.h;h=73ef4d2b13eb681e22fbc51644fbb6f2b227acc6;hb=0ee0be109fd00ec629f7a2ad6a597885a0c9d5b4;hp=d79b9affc7586ab64dc290f28a5d3d5e538723d2;hpb=b09ab92b65983635c68c8944631b1d53e9b71e42;p=ghc-hetmet.git diff --git a/includes/OSThreads.h b/includes/OSThreads.h index d79b9af..73ef4d2 100644 --- a/includes/OSThreads.h +++ b/includes/OSThreads.h @@ -23,6 +23,7 @@ #else #include +#include typedef pthread_cond_t Condition; typedef pthread_mutex_t Mutex; @@ -34,48 +35,32 @@ typedef pthread_key_t ThreadLocalKey; #define INIT_COND_VAR PTHREAD_COND_INITIALIZER #ifdef LOCK_DEBUG +#define LOCK_DEBUG_BELCH(what, mutex) \ + debugBelch("%s(0x%p) %s %d\n", what, mutex, __FILE__, __LINE__) +#else +#define LOCK_DEBUG_BELCH(what, mutex) /* nothing */ +#endif +/* Always check the result of lock and unlock. */ #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) -#define ASSERT_LOCK_HELD(mutex) /* nothing */ - -#elif defined(DEBUG) && defined(linux_HOST_OS) -#include -/* - * On Linux, we can use extensions to determine whether we already - * hold a lock or not, which is useful for debugging. - */ -#define ACQUIRE_LOCK(mutex) \ + LOCK_DEBUG_BELCH("ACQUIRE_LOCK", mutex); \ if (pthread_mutex_lock(mutex) == EDEADLK) { \ barf("multiple ACQUIRE_LOCK: %s %d", __FILE__,__LINE__); \ } + #define RELEASE_LOCK(mutex) \ + LOCK_DEBUG_BELCH("RELEASE_LOCK", mutex); \ if (pthread_mutex_unlock(mutex) != 0) { \ barf("RELEASE_LOCK: I do not own this lock: %s %d", __FILE__,__LINE__); \ } +// Note: this assertion calls pthread_mutex_lock() on a mutex that +// is already held by the calling thread. The mutex should therefore +// have been created with PTHREAD_MUTEX_ERRORCHECK, otherwise this +// assertion will hang. We always initialise mutexes with +// PTHREAD_MUTEX_ERRORCHECK when DEBUG is on (see rts/posix/OSThreads.h). #define ASSERT_LOCK_HELD(mutex) ASSERT(pthread_mutex_lock(mutex) == EDEADLK) -#define ASSERT_LOCK_NOTHELD(mutex) \ - if (pthread_mutex_lock(mutex) != EDEADLK) { \ - pthread_mutex_unlock(mutex); \ - } else { \ - ASSERT(0); \ - } - - -#else - -#define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex) -#define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex) -#define ASSERT_LOCK_HELD(mutex) /* nothing */ - -#endif - #endif // CMINUSMINUS # elif defined(HAVE_WINDOWS_H) @@ -200,6 +185,9 @@ void *getThreadLocalVar (ThreadLocalKey *key); void setThreadLocalVar (ThreadLocalKey *key, void *value); void freeThreadLocalKey (ThreadLocalKey *key); +// Processors and affinity +nat getNumberOfProcessors (void); + #endif // !CMINUSMINUS #else