Threads.h 2.31 KB
Newer Older
1 2
/* -----------------------------------------------------------------------------
 *
Simon Marlow's avatar
Simon Marlow committed
3
 * (c) The GHC Team 1998-2009
4 5 6 7
 *
 * External API for the scheduler.  For most uses, the functions in
 * RtsAPI.h should be enough.
 *
8 9 10
 * Do not #include this file directly: #include "Rts.h" instead.
 *
 * 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
 * ---------------------------------------------------------------------------*/

Simon Marlow's avatar
Simon Marlow committed
15 16
#ifndef RTS_THREADS_H
#define RTS_THREADS_H
17

Ian Lynagh's avatar
Ian Lynagh committed
18 19 20 21
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

22
//
Simon Marlow's avatar
Simon Marlow committed
23 24
// Creating threads
//
25
StgTSO *createThread (Capability *cap, W_ stack_size);
sof's avatar
sof committed
26

27 28 29
void scheduleWaitThread (/* in    */ StgTSO *tso,
                         /* out   */ HaskellObj* ret,
                         /* 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);
Simon Marlow's avatar
Simon Marlow committed
37 38

// Suspending/resuming threads around foreign calls
39
void *        suspendThread (StgRegTable *, rtsBool interruptible);
Simon Marlow's avatar
Simon Marlow committed
40 41 42 43 44
StgRegTable * resumeThread  (void *);

//
// Thread operations from Threads.c
//
45 46 47 48 49 50
int     cmp_thread                       (StgPtr tso1, StgPtr tso2);
int     rts_getThreadId                  (StgPtr tso);
HsInt64 rts_getThreadAllocationCounter   (StgPtr tso);
void    rts_setThreadAllocationCounter   (StgPtr tso, HsInt64 i);
void    rts_enableThreadAllocationLimit  (StgPtr tso);
void    rts_disableThreadAllocationLimit (StgPtr tso);
Simon Marlow's avatar
Simon Marlow committed
51 52

#if !defined(mingw32_HOST_OS)
Simon Marlow's avatar
Simon Marlow committed
53
pid_t  forkProcess     (HsStablePtr *entry);
Simon Marlow's avatar
Simon Marlow committed
54 55 56 57 58
#else
pid_t  forkProcess     (HsStablePtr *entry)
    GNU_ATTRIBUTE(__noreturn__);
#endif

Simon Marlow's avatar
Simon Marlow committed
59 60 61 62 63
HsBool rtsSupportsBoundThreads (void);

// The number of Capabilities
extern unsigned int n_capabilities;

64
// The number of Capabilities that are not disabled
65
extern uint32_t enabled_capabilities;
66

Simon Marlow's avatar
Simon Marlow committed
67 68
#if !IN_STG_CODE
extern Capability MainCapability;
69
#endif
Simon Marlow's avatar
Simon Marlow committed
70

71 72 73 74
//
// Change the number of capabilities (only supports increasing the
// current value at the moment).
//
75
extern void setNumCapabilities (uint32_t new_);
76

Simon Marlow's avatar
Simon Marlow committed
77
#endif /* RTS_THREADS_H */