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) fprintf(stderr, "ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); fflush(stderr); pthread_mutex_lock(mutex)
25 #define RELEASE_LOCK(mutex) fprintf(stderr, "RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); fflush(stderr); 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)
34 typedef HANDLE Condition;
36 typedef DWORD OSThreadId;
38 #define INIT_MUTEX_VAR 0
39 #define INIT_COND_VAR 0
42 ACQUIRE_LOCK(Mutex *mutex)
44 if (WaitForSingleObject(*mutex,INFINITE) == WAIT_FAILED) {
45 barf("WaitForSingleObject: %d", GetLastError());
50 RELEASE_LOCK(Mutex *mutex)
52 if (ReleaseMutex(*mutex) == 0) {
53 barf("ReleaseMutex: %d", GetLastError());
58 # error "Threads not supported"
61 extern void initCondition ( Condition* pCond );
62 extern void closeCondition ( Condition* pCond );
63 extern rtsBool broadcastCondition ( Condition* pCond );
64 extern rtsBool signalCondition ( Condition* pCond );
65 extern rtsBool waitCondition ( Condition* pCond,
68 extern void initMutex ( Mutex* pMut );
70 extern OSThreadId osThreadId ( void );
71 extern void shutdownThread ( void );
72 extern void yieldThread ( void );
73 extern int createOSThread ( OSThreadId* tid,
74 void (*startProc)(void) );
77 #define ACQUIRE_LOCK(l)
78 #define RELEASE_LOCK(l)
80 #endif /* defined(RTS_SUPPORTS_THREADS) */
82 #endif /* __OSTHREADS_H__ */