projects
/
ghc-hetmet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3290772
)
add TRY_ACQUIRE_LOCK()
author
Simon Marlow
<marlowsd@gmail.com>
Wed, 2 Feb 2011 11:32:42 +0000
(11:32 +0000)
committer
Simon Marlow
<marlowsd@gmail.com>
Wed, 2 Feb 2011 11:32:42 +0000
(11:32 +0000)
includes/rts/OSThreads.h
patch
|
blob
|
history
diff --git
a/includes/rts/OSThreads.h
b/includes/rts/OSThreads.h
index
5d3e6ba
..
ee59a5f
100644
(file)
--- a/
includes/rts/OSThreads.h
+++ b/
includes/rts/OSThreads.h
@@
-53,6
+53,14
@@
typedef pthread_key_t ThreadLocalKey;
barf("multiple ACQUIRE_LOCK: %s %d", __FILE__,__LINE__); \
}
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) { \
#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
#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.
// I don't know how to do this. TryEnterCriticalSection() doesn't do
// the right thing.