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