Threads.h 1.98 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

Simon Marlow's avatar
Simon Marlow committed
22 23 24
// 
// Creating threads
//
Simon Marlow's avatar
Simon Marlow committed
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

Simon Marlow's avatar
Simon Marlow committed
31
StgTSO *createGenThread       (Capability *cap, W_ stack_size,
32
			       StgClosure *closure);
Simon Marlow's avatar
Simon Marlow committed
33
StgTSO *createIOThread        (Capability *cap, W_ stack_size,
34
			       StgClosure *closure);
Simon Marlow's avatar
Simon Marlow committed
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 45 46
StgRegTable * resumeThread  (void *);

//
// Thread operations from Threads.c
//
int    cmp_thread      (StgPtr tso1, StgPtr tso2);
int    rts_getThreadId (StgPtr tso);
Simon Marlow's avatar
Simon Marlow committed
47 48

#if !defined(mingw32_HOST_OS)
Simon Marlow's avatar
Simon Marlow committed
49
pid_t  forkProcess     (HsStablePtr *entry);
Simon Marlow's avatar
Simon Marlow committed
50 51 52 53 54
#else
pid_t  forkProcess     (HsStablePtr *entry)
    GNU_ATTRIBUTE(__noreturn__);
#endif

Simon Marlow's avatar
Simon Marlow committed
55 56 57 58 59
HsBool rtsSupportsBoundThreads (void);

// The number of Capabilities
extern unsigned int n_capabilities;

60 61 62
// The number of Capabilities that are not disabled
extern nat enabled_capabilities;

Simon Marlow's avatar
Simon Marlow committed
63 64
#if !IN_STG_CODE
extern Capability MainCapability;
65
#endif
Simon Marlow's avatar
Simon Marlow committed
66

67 68 69 70
//
// Change the number of capabilities (only supports increasing the
// current value at the moment).
//
71
extern void setNumCapabilities (nat new_);
72

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