From f9a1e689ac9b5bfea3a4af406f59b7e46cbf1ffe Mon Sep 17 00:00:00 2001 From: simonm <unknown> Date: Tue, 26 Jan 1999 14:04:46 +0000 Subject: [PATCH] [project @ 1999-01-26 14:04:46 by simonm] add missing file. --- ghc/includes/Stable.h | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ghc/includes/Stable.h diff --git a/ghc/includes/Stable.h b/ghc/includes/Stable.h new file mode 100644 index 000000000000..7ffa369d5fdd --- /dev/null +++ b/ghc/includes/Stable.h @@ -0,0 +1,62 @@ +/* ----------------------------------------------------------------------------- + * $Id: Stable.h,v 1.1 1999/01/26 14:04:46 simonm Exp $ + * + * Stable names and stable pointers + * + * ---------------------------------------------------------------------------*/ + +/* ----------------------------------------------------------------------------- + External C Interface + -------------------------------------------------------------------------- */ + +extern StgPtr deRefStablePtr(StgStablePtr stable_ptr); +extern void freeStablePtr(StgStablePtr sp); +extern StgStablePtr splitStablePtr(StgStablePtr sp); + +/* ----------------------------------------------------------------------------- + PRIVATE from here. + -------------------------------------------------------------------------- */ + +extern StgStablePtr getStablePtr(StgPtr p); + +typedef struct { + StgPtr addr; /* either Haskell object or free list */ + StgWord weight; /* used for reference counting */ + unsigned int keep; /* set by the garbage collector */ +} snEntry; + +extern snEntry *stable_ptr_table; +extern snEntry *stable_ptr_free; + +extern unsigned int SPT_size; + +extern inline StgPtr +deRefStablePtr(StgStablePtr sp) +{ + ASSERT(stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].weight > 0); + return stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].addr; +} + +extern inline void +freeStablePtr(StgStablePtr sp) +{ + StgWord sn = sp & ~STABLEPTR_WEIGHT_MASK; + + ASSERT(sn < SPT_size + && stable_ptr_table[sn].addr != NULL + && stable_ptr_table[sn].weight > 0); + + stable_ptr_table[sn].weight += (sp & STABLEPTR_WEIGHT_MASK) >> STABLEPTR_WEIGHT_SHIFT; +} + +extern inline StgStablePtr +splitStablePtr(StgStablePtr sp) +{ + /* doesn't need access to the stable pointer table */ + StgWord weight = (sp & STABLEPTR_WEIGHT_MASK) / 2; + return (sp & ~STABLEPTR_WEIGHT_MASK) + weight; +} + +/* No deRefStableName, because the existence of a stable name doesn't + * guarantee the existence of the object itself. + */ -- GitLab