8d52e329a91f7f7b3fdee364ae73af23ec304dc9
[ghc-hetmet.git] / ghc / rts / BlockAlloc.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-1999
4  *
5  * Block Allocator Interface
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef BLOCK_ALLOC_H
10 #define BLOCK_ALLOC_H
11
12 /* Initialisation ---------------------------------------------------------- */
13
14 extern void initBlockAllocator(void);
15
16 /* Allocation -------------------------------------------------------------- */
17
18 extern bdescr *allocGroup(nat n);
19 extern bdescr *allocBlock(void);
20
21 /* De-Allocation ----------------------------------------------------------- */
22
23 extern void freeGroup(bdescr *p);
24 extern void freeChain(bdescr *p);
25
26 /* Round a value to megablocks --------------------------------------------- */
27
28 #define WORDS_PER_MBLOCK  (BLOCKS_PER_MBLOCK * BLOCK_SIZE_W)
29
30 INLINE_HEADER nat
31 round_to_mblocks(nat words)
32 {
33   if (words > WORDS_PER_MBLOCK) {
34     if ((words % WORDS_PER_MBLOCK) < (WORDS_PER_MBLOCK / 2)) {
35       words = (words / WORDS_PER_MBLOCK) * WORDS_PER_MBLOCK;
36     } else {
37       words = ((words / WORDS_PER_MBLOCK) + 1) * WORDS_PER_MBLOCK;
38     }
39   }
40   return words;
41 }
42
43 /* Debugging  -------------------------------------------------------------- */
44
45 #ifdef DEBUG
46 extern void checkFreeListSanity(void);
47 nat         countFreeList(void);
48 #endif
49
50 #endif /* BLOCK_ALLOC_H */