[project @ 2002-02-04 20:18:26 by sof]
[ghc-hetmet.git] / ghc / rts / OSThreads.h
1 /* ---------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 2001
4  *
5  * Accessing OS threads functionality in a (mostly) OS-independent
6  * manner. 
7  *
8  * 
9  * --------------------------------------------------------------------------*/
10 #ifndef __OSTHREADS_H__
11 #define __OSTHREADS_H__
12 #if defined(RTS_SUPPORTS_THREADS) /*to the end */
13
14 # if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS)
15 #  include <pthread.h>
16 typedef pthread_cond_t  Condition;
17 typedef pthread_mutex_t Mutex;
18 typedef pthread_t       OSThreadId;
19
20 #define INIT_MUTEX_VAR      PTHREAD_MUTEX_INITIALIZER
21 #define INIT_COND_VAR       PTHREAD_COND_INITIALIZER
22
23 #define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex)
24 #define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex)
25
26 # elif defined(HAVE_WINDOWS_H)
27 #include <windows.h>
28
29 typedef HANDLE Condition;
30 typedef HANDLE Mutex;
31 typedef DWORD OSThreadId;
32
33 #define INIT_MUTEX_VAR 0
34 #define INIT_COND_VAR  0
35
36 #define ACQURE_LOCK(mutex)    WaitForSingleObject(mutex,INFINITE)
37 #define RELEASE_LOCK(mutex)   ReleaseMutex(handle)
38 #define 
39 # else
40 #  error "Threads not supported"
41 # endif
42
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, 
48                                     Mutex* pMut );
49
50 extern void initMutex             ( Mutex* pMut );
51
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) );
57 #else
58
59 #define ACQUIRE_LOCK(l)
60 #define RELEASE_LOCK(l)
61
62 #endif /* defined(RTS_SUPPORTS_THREADS) */
63
64 #endif /* __OSTHREADS_H__ */