1 /* -----------------------------------------------------------------------------
2 * $Id: Stable.h,v 1.1 1999/01/26 14:04:46 simonm Exp $
4 * Stable names and stable pointers
6 * ---------------------------------------------------------------------------*/
8 /* -----------------------------------------------------------------------------
10 -------------------------------------------------------------------------- */
12 extern StgPtr deRefStablePtr(StgStablePtr stable_ptr);
13 extern void freeStablePtr(StgStablePtr sp);
14 extern StgStablePtr splitStablePtr(StgStablePtr sp);
16 /* -----------------------------------------------------------------------------
18 -------------------------------------------------------------------------- */
20 extern StgStablePtr getStablePtr(StgPtr p);
23 StgPtr addr; /* either Haskell object or free list */
24 StgWord weight; /* used for reference counting */
25 unsigned int keep; /* set by the garbage collector */
28 extern snEntry *stable_ptr_table;
29 extern snEntry *stable_ptr_free;
31 extern unsigned int SPT_size;
34 deRefStablePtr(StgStablePtr sp)
36 ASSERT(stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].weight > 0);
37 return stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].addr;
41 freeStablePtr(StgStablePtr sp)
43 StgWord sn = sp & ~STABLEPTR_WEIGHT_MASK;
46 && stable_ptr_table[sn].addr != NULL
47 && stable_ptr_table[sn].weight > 0);
49 stable_ptr_table[sn].weight += (sp & STABLEPTR_WEIGHT_MASK) >> STABLEPTR_WEIGHT_SHIFT;
52 extern inline StgStablePtr
53 splitStablePtr(StgStablePtr sp)
55 /* doesn't need access to the stable pointer table */
56 StgWord weight = (sp & STABLEPTR_WEIGHT_MASK) / 2;
57 return (sp & ~STABLEPTR_WEIGHT_MASK) + weight;
60 /* No deRefStableName, because the existence of a stable name doesn't
61 * guarantee the existence of the object itself.