67d01db7d401cd1bdf21d85bfc1c0bc642cd772d
[ghc.git] / includes / rts / Threads.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 1998-2009
4 *
5 * External API for the scheduler. For most uses, the functions in
6 * RtsAPI.h should be enough.
7 *
8 * Do not #include this file directly: #include "Rts.h" instead.
9 *
10 * To understand the structure of the RTS headers, see the wiki:
11 * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
12 *
13 * ---------------------------------------------------------------------------*/
14
15 #ifndef RTS_THREADS_H
16 #define RTS_THREADS_H
17
18 #ifdef HAVE_SYS_TYPES_H
19 #include <sys/types.h>
20 #endif
21
22 //
23 // Creating threads
24 //
25 StgTSO *createThread (Capability *cap, W_ stack_size);
26
27 void scheduleWaitThread (/* in */ StgTSO *tso,
28 /* out */ HaskellObj* ret,
29 /* inout */ Capability **cap);
30
31 StgTSO *createGenThread (Capability *cap, W_ stack_size,
32 StgClosure *closure);
33 StgTSO *createIOThread (Capability *cap, W_ stack_size,
34 StgClosure *closure);
35 StgTSO *createStrictIOThread (Capability *cap, W_ stack_size,
36 StgClosure *closure);
37
38 // Suspending/resuming threads around foreign calls
39 void * suspendThread (StgRegTable *, rtsBool interruptible);
40 StgRegTable * resumeThread (void *);
41
42 //
43 // Thread operations from Threads.c
44 //
45 int cmp_thread (StgPtr tso1, StgPtr tso2);
46 int rts_getThreadId (StgPtr tso);
47 HsInt64 rts_getThreadAllocationCounter (StgPtr tso);
48 void rts_setThreadAllocationCounter (StgPtr tso, HsInt64 i);
49 void rts_enableThreadAllocationLimit (StgPtr tso);
50 void rts_disableThreadAllocationLimit (StgPtr tso);
51
52 #if !defined(mingw32_HOST_OS)
53 pid_t forkProcess (HsStablePtr *entry);
54 #else
55 pid_t forkProcess (HsStablePtr *entry)
56 GNU_ATTRIBUTE(__noreturn__);
57 #endif
58
59 HsBool rtsSupportsBoundThreads (void);
60
61 // The number of Capabilities
62 extern unsigned int n_capabilities;
63
64 // The number of Capabilities that are not disabled
65 extern uint32_t enabled_capabilities;
66
67 #if !IN_STG_CODE
68 extern Capability MainCapability;
69 #endif
70
71 //
72 // Change the number of capabilities (only supports increasing the
73 // current value at the moment).
74 //
75 extern void setNumCapabilities (uint32_t new_);
76
77 #endif /* RTS_THREADS_H */