diff options
author | Shea Levy <shea@shealevy.com> | 2016-11-29 13:28:27 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-11-29 14:39:55 -0500 |
commit | 1732d7ac43ca578deca39ea5a63cbf34f3cd9dd5 (patch) | |
tree | 258f187815dddea45843d17e57dad0dfcfd020ac /includes | |
parent | 36e36227e438d95fae367d10183ea43b4819854f (diff) | |
download | haskell-1732d7ac43ca578deca39ea5a63cbf34f3cd9dd5.tar.gz |
Define thread primitives if they're supported.
On iOS, we use the pthread-based implementation of Itimer.c even for a
non-threaded RTS. Since 999c464, this relies on synchronization
primitives like Mutex, so ensure those primitives are defined whenever
they are supported, even if !THREADED_RTS.
Fixes #12799.
Reviewers: erikd, austin, simonmar, bgamari
Reviewed By: simonmar, bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2712
GHC Trac Issues: #12799
Diffstat (limited to 'includes')
-rw-r--r-- | includes/rts/OSThreads.h | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h index 2eb58971ca..efd24066b6 100644 --- a/includes/rts/OSThreads.h +++ b/includes/rts/OSThreads.h @@ -15,15 +15,13 @@ #ifndef RTS_OSTHREADS_H #define RTS_OSTHREADS_H -#if defined(THREADED_RTS) /* to near the end */ - #if defined(HAVE_PTHREAD_H) && !defined(mingw32_HOST_OS) #if CMINUSMINUS -#define ACQUIRE_LOCK(mutex) foreign "C" pthread_mutex_lock(mutex) -#define RELEASE_LOCK(mutex) foreign "C" pthread_mutex_unlock(mutex) -#define ASSERT_LOCK_HELD(mutex) /* nothing */ +#define OS_ACQUIRE_LOCK(mutex) foreign "C" pthread_mutex_lock(mutex) +#define OS_RELEASE_LOCK(mutex) foreign "C" pthread_mutex_unlock(mutex) +#define OS_ASSERT_LOCK_HELD(mutex) /* nothing */ #else @@ -47,7 +45,7 @@ typedef pthread_key_t ThreadLocalKey; #endif /* Always check the result of lock and unlock. */ -#define ACQUIRE_LOCK(mutex) \ +#define OS_ACQUIRE_LOCK(mutex) \ LOCK_DEBUG_BELCH("ACQUIRE_LOCK", mutex); \ if (pthread_mutex_lock(mutex) == EDEADLK) { \ barf("multiple ACQUIRE_LOCK: %s %d", __FILE__,__LINE__); \ @@ -61,7 +59,7 @@ EXTERN_INLINE int TRY_ACQUIRE_LOCK(pthread_mutex_t *mutex) return pthread_mutex_trylock(mutex); } -#define RELEASE_LOCK(mutex) \ +#define OS_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__); \ @@ -72,7 +70,7 @@ EXTERN_INLINE int TRY_ACQUIRE_LOCK(pthread_mutex_t *mutex) // 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 OS_ASSERT_LOCK_HELD(mutex) ASSERT(pthread_mutex_lock(mutex) == EDEADLK) #endif // CMINUSMINUS @@ -83,9 +81,9 @@ EXTERN_INLINE int TRY_ACQUIRE_LOCK(pthread_mutex_t *mutex) /* We jump through a hoop here to get a CCall EnterCriticalSection and LeaveCriticalSection, as that's what C-- wants. */ -#define ACQUIRE_LOCK(mutex) foreign "stdcall" EnterCriticalSection(mutex) -#define RELEASE_LOCK(mutex) foreign "stdcall" LeaveCriticalSection(mutex) -#define ASSERT_LOCK_HELD(mutex) /* nothing */ +#define OS_ACQUIRE_LOCK(mutex) foreign "stdcall" EnterCriticalSection(mutex) +#define OS_RELEASE_LOCK(mutex) foreign "stdcall" LeaveCriticalSection(mutex) +#define OS_ASSERT_LOCK_HELD(mutex) /* nothing */ #else @@ -115,23 +113,23 @@ typedef CRITICAL_SECTION Mutex; #ifdef LOCK_DEBUG -#define ACQUIRE_LOCK(mutex) \ +#define OS_ACQUIRE_LOCK(mutex) \ debugBelch("ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); \ EnterCriticalSection(mutex) -#define RELEASE_LOCK(mutex) \ +#define OS_RELEASE_LOCK(mutex) \ debugBelch("RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); \ LeaveCriticalSection(mutex) -#define ASSERT_LOCK_HELD(mutex) /* nothing */ +#define OS_ASSERT_LOCK_HELD(mutex) /* nothing */ #else -#define ACQUIRE_LOCK(mutex) EnterCriticalSection(mutex) +#define OS_ACQUIRE_LOCK(mutex) EnterCriticalSection(mutex) #define TRY_ACQUIRE_LOCK(mutex) (TryEnterCriticalSection(mutex) == 0) -#define RELEASE_LOCK(mutex) LeaveCriticalSection(mutex) +#define OS_RELEASE_LOCK(mutex) LeaveCriticalSection(mutex) // I don't know how to do this. TryEnterCriticalSection() doesn't do // the right thing. -#define ASSERT_LOCK_HELD(mutex) /* nothing */ +#define OS_ASSERT_LOCK_HELD(mutex) /* nothing */ #endif @@ -141,22 +139,22 @@ typedef HANDLE Mutex; // casting to (Mutex *) here required due to use in .cmm files where // the argument has (void *) type. -#define ACQUIRE_LOCK(mutex) \ +#define OS_ACQUIRE_LOCK(mutex) \ if (WaitForSingleObject(*((Mutex *)mutex),INFINITE) == WAIT_FAILED) { \ barf("WaitForSingleObject: %d", GetLastError()); \ } -#define RELEASE_LOCK(mutex) \ +#define OS_RELEASE_LOCK(mutex) \ if (ReleaseMutex(*((Mutex *)mutex)) == 0) { \ barf("ReleaseMutex: %d", GetLastError()); \ } -#define ASSERT_LOCK_HELD(mutex) /* nothing */ +#define OS_ASSERT_LOCK_HELD(mutex) /* nothing */ #endif #endif // CMINUSMINUS -# else +# elif defined(THREADED_RTS) # error "Threads not supported" # endif @@ -205,6 +203,12 @@ void setThreadNode (uint32_t node); void releaseThreadNode (void); #endif // !CMINUSMINUS +#ifdef THREADED_RTS + +#define ACQUIRE_LOCK(l) OS_ACQUIRE_LOCK(l) +#define RELEASE_LOCK(l) OS_RELEASE_LOCK(l) +#define ASSERT_LOCK_HELD(l) OS_ASSERT_LOCK_HELD(l) + #else #define ACQUIRE_LOCK(l) |