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
41 #define ACQUIRE_LOCK(mutex) WaitForSingleObject(mutex,INFINITE)
42 #define RELEASE_LOCK(mutex) ReleaseMutex(mutex)
44 # error "Threads not supported"
47 extern void initCondition ( Condition* pCond );
48 extern void closeCondition ( Condition* pCond );
49 extern rtsBool broadcastCondition ( Condition* pCond );
50 extern rtsBool signalCondition ( Condition* pCond );
51 extern rtsBool waitCondition ( Condition* pCond,
54 extern void initMutex ( Mutex* pMut );
56 extern OSThreadId osThreadId ( void );
57 extern void shutdownThread ( void );
58 extern void yieldThread ( void );
59 extern int createOSThread ( OSThreadId* tid,
60 void (*startProc)(void) );
63 #define ACQUIRE_LOCK(l)
64 #define RELEASE_LOCK(l)
66 #endif /* defined(RTS_SUPPORTS_THREADS) */
68 #endif /* __OSTHREADS_H__ */