diff options
author | Simon Marlow <marlowsd@gmail.com> | 2009-01-16 11:43:39 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2009-01-16 11:43:39 +0000 |
commit | b2d4af35427f9b195ba9987f5ce6b48fb2a5de64 (patch) | |
tree | 18523cab2d9b5e27385417c6af60f87ab38c9f9a /includes | |
parent | 09c5b3c4ef3dcbaa35d829d57edf25eca279f8c1 (diff) | |
download | haskell-b2d4af35427f9b195ba9987f5ce6b48fb2a5de64.tar.gz |
UNDO: Always check the result of pthread_mutex_lock() and pthread_mutex_unlock().
This patch caused problems on Mac OS X, undoing until we can do it better.
rolling back:
Sun Jan 4 19:24:43 GMT 2009 Matthias Kilian <kili@outback.escape.de>
* Always check the result of pthread_mutex_lock() and pthread_mutex_unlock().
Don't check pthread_mutex_*lock() only on Linux and/or only if DEBUG
is defined. The return values of those functions are well defined
and should be supported on all operation systems with pthreads. The
checks are cheap enough to do them even in the default build (without
-DDEBUG).
While here, recycle an unused macro ASSERT_LOCK_NOTHELD, and let
the debugBelch part enabled with -DLOCK_DEBUG work independently
of -DDEBUG.
M ./includes/OSThreads.h -30 +10
Diffstat (limited to 'includes')
-rw-r--r-- | includes/OSThreads.h | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/includes/OSThreads.h b/includes/OSThreads.h index fd57f56606..d79b9affc7 100644 --- a/includes/OSThreads.h +++ b/includes/OSThreads.h @@ -23,7 +23,6 @@ #else #include <pthread.h> -#include <errno.h> typedef pthread_cond_t Condition; typedef pthread_mutex_t Mutex; @@ -35,27 +34,48 @@ 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) \ - LOCK_DEBUG_BELCH("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 <errno.h> +/* + * 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) \ 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__); \ } #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) |