1 /* -----------------------------------------------------------------------------
2 * $Id: Stable.h,v 1.4 1999/03/02 19:44:16 sof Exp $
4 * (c) The GHC Team, 1998-1999
6 * Stable names and stable pointers
8 * ---------------------------------------------------------------------------*/
10 /* -----------------------------------------------------------------------------
12 -------------------------------------------------------------------------- */
14 extern StgPtr deRefStablePtr(StgStablePtr stable_ptr);
15 extern void freeStablePtr(StgStablePtr sp);
16 extern StgStablePtr splitStablePtr(StgStablePtr sp);
18 /* -----------------------------------------------------------------------------
20 -------------------------------------------------------------------------- */
22 extern StgStablePtr getStablePtr(StgPtr p);
25 StgPtr addr; /* Haskell object, free list, or NULL */
26 StgWord weight; /* used for reference counting */
27 StgClosure *sn_obj; /* the StableName object (or NULL) */
30 extern DLL_IMPORT_RTS snEntry *stable_ptr_table;
31 extern DLL_IMPORT_RTS snEntry *stable_ptr_free;
33 extern DLL_IMPORT_RTS unsigned int SPT_size;
36 deRefStablePtr(StgStablePtr sp)
38 ASSERT(stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].weight > 0);
39 return stable_ptr_table[sp & ~STABLEPTR_WEIGHT_MASK].addr;
43 freeStablePtr(StgStablePtr sp)
45 StgWord sn = sp & ~STABLEPTR_WEIGHT_MASK;
48 && stable_ptr_table[sn].addr != NULL
49 && stable_ptr_table[sn].weight > 0);
51 stable_ptr_table[sn].weight += (sp & STABLEPTR_WEIGHT_MASK) >> STABLEPTR_WEIGHT_SHIFT;
54 extern inline StgStablePtr
55 splitStablePtr(StgStablePtr sp)
57 /* doesn't need access to the stable pointer table */
58 StgWord weight = (sp & STABLEPTR_WEIGHT_MASK) / 2;
59 return (sp & ~STABLEPTR_WEIGHT_MASK) + weight;
62 /* No deRefStableName, because the existence of a stable name doesn't
63 * guarantee the existence of the object itself.