1 /* ---------------------------------------------------------------------------
3 * (c) The GHC Team, 2001
5 * Accessing OS threads functionality in a (mostly) OS-independent
9 * --------------------------------------------------------------------------*/
10 #ifndef __OSTHREADS_H__
11 #define __OSTHREADS_H__
12 #if defined(RTS_SUPPORTS_THREADS) /* to the end */
14 # if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS)
16 typedef pthread_cond_t Condition;
17 typedef pthread_mutex_t Mutex;
18 typedef pthread_t OSThreadId;
20 #define INIT_MUTEX_VAR PTHREAD_MUTEX_INITIALIZER
21 #define INIT_COND_VAR PTHREAD_COND_INITIALIZER
24 #define ACQUIRE_LOCK(mutex) debugBelch("ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); pthread_mutex_lock(mutex)
25 #define RELEASE_LOCK(mutex) debugBelch("RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); pthread_mutex_unlock(mutex)
27 #define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex)
28 #define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex)
31 # elif defined(HAVE_WINDOWS_H)
36 typedef HANDLE Condition;
38 typedef DWORD OSThreadId;
40 #define INIT_MUTEX_VAR 0
41 #define INIT_COND_VAR 0
44 ACQUIRE_LOCK(Mutex *mutex)
46 if (WaitForSingleObject(*mutex,INFINITE) == WAIT_FAILED) {
47 barf("WaitForSingleObject: %d", GetLastError());
52 RELEASE_LOCK(Mutex *mutex)
54 if (ReleaseMutex(*mutex) == 0) {
55 barf("ReleaseMutex: %d", GetLastError());
60 # error "Threads not supported"
63 extern void initCondition ( Condition* pCond );
64 extern void closeCondition ( Condition* pCond );
65 extern rtsBool broadcastCondition ( Condition* pCond );
66 extern rtsBool signalCondition ( Condition* pCond );
67 extern rtsBool waitCondition ( Condition* pCond,
70 extern void initMutex ( Mutex* pMut );
72 extern OSThreadId osThreadId ( void );
73 extern void shutdownThread ( void );
74 extern void yieldThread ( void );
75 extern int createOSThread ( OSThreadId* tid,
76 void (*startProc)(void) );
79 #define ACQUIRE_LOCK(l)
80 #define RELEASE_LOCK(l)
82 #endif /* defined(RTS_SUPPORTS_THREADS) */
84 #endif /* __OSTHREADS_H__ */