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
23 #define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex)
24 #define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex)
26 # elif defined(HAVE_WINDOWS_H)
29 typedef HANDLE Condition;
31 typedef DWORD OSThreadId;
33 #define INIT_MUTEX_VAR 0
34 #define INIT_COND_VAR 0
36 #define ACQURE_LOCK(mutex) WaitForSingleObject(mutex,INFINITE)
37 #define RELEASE_LOCK(mutex) ReleaseMutex(handle)
40 # error "Threads not supported"
43 extern void initCondition ( Condition* pCond );
44 extern void closeCondition ( Condition* pCond );
45 extern rtsBool broadcastCondition ( Condition* pCond );
46 extern rtsBool signalCondition ( Condition* pCond );
47 extern rtsBool waitCondition ( Condition* pCond,
50 extern void initMutex ( Mutex* pMut );
52 extern OSThreadId osThreadId ( void );
53 extern void shutdownThread ( void );
54 extern void yieldThread ( void );
55 extern int createOSThread ( OSThreadId* tid,
56 void (*startProc)(void) );
59 #define ACQUIRE_LOCK(l)
60 #define RELEASE_LOCK(l)
62 #endif /* defined(RTS_SUPPORTS_THREADS) */
64 #endif /* __OSTHREADS_H__ */