1 /* -----------------------------------------------------------------------------
2 * $Id: BlockAlloc.h,v 1.4 1999/02/03 16:32:47 simonm Exp $
4 * Block Allocator Interface
6 * ---------------------------------------------------------------------------*/
11 /* Initialisation ---------------------------------------------------------- */
13 extern void initBlockAllocator(void);
15 /* Allocation -------------------------------------------------------------- */
17 extern bdescr *allocGroup(nat n);
18 extern bdescr *allocBlock(void);
20 /* De-Allocation ----------------------------------------------------------- */
22 extern void freeGroup(bdescr *p);
23 extern void freeChain(bdescr *p);
25 /* Finding the block descriptor for a given block -------------------------- */
27 static inline bdescr *Bdescr(StgPtr p)
30 ((((W_)p & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT))
31 | ((W_)p & ~MBLOCK_MASK)
35 /* Round a value to megablocks --------------------------------------------- */
37 #define WORDS_PER_MBLOCK (BLOCKS_PER_MBLOCK * BLOCK_SIZE_W)
40 round_to_mblocks(nat words)
42 if (words > WORDS_PER_MBLOCK) {
43 if ((words % WORDS_PER_MBLOCK) < (WORDS_PER_MBLOCK / 2)) {
44 words = (words / WORDS_PER_MBLOCK) * WORDS_PER_MBLOCK;
46 words = ((words / WORDS_PER_MBLOCK) + 1) * WORDS_PER_MBLOCK;
52 /* Debugging -------------------------------------------------------------- */
55 extern void checkFreeListSanity(void);
56 nat countFreeList(void);