X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fincludes%2FBlock.h;h=d1705ad68650afddb9451d415d6f3d3db1c9a0b8;hb=28a464a75e14cece5db40f2765a29348273ff2d2;hp=f924a8e93f2e47717f4120ae5f84934a276f37f7;hpb=7f309f1c021e7583f724cce599ce2dd3c439361b;p=ghc-hetmet.git diff --git a/ghc/includes/Block.h b/ghc/includes/Block.h index f924a8e..d1705ad 100644 --- a/ghc/includes/Block.h +++ b/ghc/includes/Block.h @@ -1,5 +1,4 @@ /* ----------------------------------------------------------------------------- - * $Id: Block.h,v 1.4 1999/02/05 16:02:19 simonm Exp $ * * (c) The GHC Team, 1998-1999 * @@ -14,22 +13,29 @@ * includes/Constants.h, all constants here are derived from these. */ -/* Block related constants (4k blocks) */ +/* Block related constants (BLOCK_SHIFT is defined in Constants.h) */ +#define BLOCK_SIZE (1<> (BLOCK_SHIFT-BDESCR_SHIFT)) \ + | ((p) & ~MBLOCK_MASK)) + +#else + +INLINE_HEADER bdescr *Bdescr(StgPtr p) +{ + return (bdescr *) + ((((W_)p & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT)) + | ((W_)p & ~MBLOCK_MASK) + ); +} + +#endif + /* Useful Macros ------------------------------------------------------------ */ /* Offset of first real data block in a megablock */ #define FIRST_BLOCK_OFF \ - ((W_)BLOCK_ROUND_UP(MBLOCK_SIZE / BLOCK_SIZE * BDESCR_SIZE)) + ((W_)BLOCK_ROUND_UP(BDESCR_SIZE * (MBLOCK_SIZE / BLOCK_SIZE))) /* First data block in a given megablock */ @@ -100,4 +142,61 @@ typedef struct _bdescr { #define BLOCKS_TO_MBLOCKS(n) \ (1 + (W_)MBLOCK_ROUND_UP((n-BLOCKS_PER_MBLOCK) * BLOCK_SIZE) / MBLOCK_SIZE) -#endif BLOCK_H + +#ifndef CMINUSMINUS +/* to the end... */ + +/* Double-linked block lists: --------------------------------------------- */ + +INLINE_HEADER void +dbl_link_onto(bdescr *bd, bdescr **list) +{ + bd->link = *list; + bd->u.back = NULL; + if (*list) { + (*list)->u.back = bd; /* double-link the list */ + } + *list = bd; +} + +/* Initialisation ---------------------------------------------------------- */ + +extern void initBlockAllocator(void); + +/* Allocation -------------------------------------------------------------- */ + +bdescr *allocGroup(nat n); +bdescr *allocBlock(void); + +// versions that take the storage manager lock for you: +bdescr *allocGroup_lock(nat n); +bdescr *allocBlock_lock(void); + +/* De-Allocation ----------------------------------------------------------- */ + +void freeGroup(bdescr *p); +void freeChain(bdescr *p); + +// versions that take the storage manager lock for you: +void freeGroup_lock(bdescr *p); +void freeChain_lock(bdescr *p); + +/* Round a value to megablocks --------------------------------------------- */ + +#define WORDS_PER_MBLOCK (BLOCKS_PER_MBLOCK * BLOCK_SIZE_W) + +INLINE_HEADER nat +round_to_mblocks(nat words) +{ + if (words > WORDS_PER_MBLOCK) { + if ((words % WORDS_PER_MBLOCK) < (WORDS_PER_MBLOCK / 2)) { + words = (words / WORDS_PER_MBLOCK) * WORDS_PER_MBLOCK; + } else { + words = ((words / WORDS_PER_MBLOCK) + 1) * WORDS_PER_MBLOCK; + } + } + return words; +} + +#endif /* !CMINUSMINUS */ +#endif /* BLOCK_H */