1 /* -----------------------------------------------------------------------------
2 * $Id: BlockAlloc.h,v 1.7 1999/11/02 17:08:28 simonmar Exp $
4 * (c) The GHC Team, 1998-1999
6 * Block Allocator Interface
8 * ---------------------------------------------------------------------------*/
13 /* Initialisation ---------------------------------------------------------- */
15 extern void initBlockAllocator(void);
17 /* Allocation -------------------------------------------------------------- */
19 extern bdescr *allocGroup(nat n);
20 extern bdescr *allocBlock(void);
22 /* De-Allocation ----------------------------------------------------------- */
24 extern void freeGroup(bdescr *p);
25 extern void freeChain(bdescr *p);
27 /* Finding the block descriptor for a given block -------------------------- */
29 static inline bdescr *Bdescr(StgPtr p)
32 ((((W_)p & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT))
33 | ((W_)p & ~MBLOCK_MASK)
37 /* Round a value to megablocks --------------------------------------------- */
39 #define WORDS_PER_MBLOCK (BLOCKS_PER_MBLOCK * BLOCK_SIZE_W)
42 round_to_mblocks(nat words)
44 if (words > WORDS_PER_MBLOCK) {
45 if ((words % WORDS_PER_MBLOCK) < (WORDS_PER_MBLOCK / 2)) {
46 words = (words / WORDS_PER_MBLOCK) * WORDS_PER_MBLOCK;
48 words = ((words / WORDS_PER_MBLOCK) + 1) * WORDS_PER_MBLOCK;
54 /* Debugging -------------------------------------------------------------- */
57 extern void checkFreeListSanity(void);
58 nat countFreeList(void);