[project @ 1999-02-03 16:32:47 by simonm]
[ghc-hetmet.git] / ghc / rts / BlockAlloc.h
1 /* -----------------------------------------------------------------------------
2  * $Id: BlockAlloc.h,v 1.4 1999/02/03 16:32:47 simonm Exp $
3  *
4  * Block Allocator Interface
5  *
6  * ---------------------------------------------------------------------------*/
7
8 #ifndef BLOCK_ALLOC_H
9 #define BLOCK_ALLOC_H
10
11 /* Initialisation ---------------------------------------------------------- */
12
13 extern void initBlockAllocator(void);
14
15 /* Allocation -------------------------------------------------------------- */
16
17 extern bdescr *allocGroup(nat n);
18 extern bdescr *allocBlock(void);
19
20 /* De-Allocation ----------------------------------------------------------- */
21
22 extern void freeGroup(bdescr *p);
23 extern void freeChain(bdescr *p);
24
25 /* Finding the block descriptor for a given block -------------------------- */
26
27 static inline bdescr *Bdescr(StgPtr p)
28 {
29   return (bdescr *)
30     ((((W_)p &  MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT)) 
31      | ((W_)p & ~MBLOCK_MASK)
32      );
33 }
34
35 /* Round a value to megablocks --------------------------------------------- */
36
37 #define WORDS_PER_MBLOCK  (BLOCKS_PER_MBLOCK * BLOCK_SIZE_W)
38
39 static inline nat
40 round_to_mblocks(nat words)
41 {
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;
45     } else {
46       words = ((words / WORDS_PER_MBLOCK) + 1) * WORDS_PER_MBLOCK;
47     }
48   }
49   return words;
50 }
51
52 /* Debugging  -------------------------------------------------------------- */
53
54 #ifdef DEBUG
55 extern void checkFreeListSanity(void);
56 nat         countFreeList(void);
57 #endif
58
59 #endif BLOCK_ALLOC_H