Capability.h 1.73 KB
Newer Older
sof's avatar
sof committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/* ---------------------------------------------------------------------------
 *
 * (c) The GHC Team, 2001
 *
 * Capabilities
 *
 * The notion of a capability is used when operating in multi-threaded
 * environments (which the SMP and Threads builds of the RTS do), to
 * hold all the state an OS thread/task needs to run Haskell code:
 * its STG registers, a pointer to its  TSO, a nursery etc. During
 * STG execution, a pointer to the capabilitity is kept in a 
 * register (BaseReg).
 *
 * Only in an SMP build will there be multiple capabilities, the threaded
 * RTS and other non-threaded builds, there is one global capability,
 * namely MainRegTable.
 *
 * This header file contains the functions for working with capabilities.
 * (the main, and only, consumer of this interface is the scheduler).
 * 
 * --------------------------------------------------------------------------*/
#ifndef __CAPABILITY_H__
#define __CAPABILITY_H__
#include "RtsFlags.h"
/* ToDo: assume that RtsFlags.h has been included at usage sites of Capability.h? */

sof's avatar
sof committed
27
#if !defined(SMP)
sof's avatar
sof committed
28
extern Capability MainCapability;
sof's avatar
sof committed
29 30 31 32
#endif

extern void initCapabilities(void);
extern void grabCapability(Capability** cap);
sof's avatar
sof committed
33
extern void releaseCapability(Capability* cap);
sof's avatar
sof committed
34

sof's avatar
sof committed
35
#if defined(RTS_SUPPORTS_THREADS)
sof's avatar
sof committed
36 37 38 39 40 41 42
extern nat rts_n_free_capabilities;  /* total number of available capabilities */

static inline nat getFreeCapabilities()
{
  return rts_n_free_capabilities;
}

sof's avatar
sof committed
43
static inline rtsBool noCapabilities()
sof's avatar
sof committed
44 45 46 47 48 49
{
  return (rts_n_free_capabilities == 0);
}

static inline rtsBool allFreeCapabilities()
{
sof's avatar
sof committed
50
# if defined(SMP)
sof's avatar
sof committed
51
  return (rts_n_free_capabilities == RtsFlags.ParFlags.nNodes);
sof's avatar
sof committed
52 53 54
# else
  return (rts_n_free_capabilities == 1);
# endif 
sof's avatar
sof committed
55 56
}

sof's avatar
sof committed
57
#endif /* RTS_SUPPORTS_THREADS */
sof's avatar
sof committed
58 59

#endif /* __CAPABILITY_H__ */