[project @ 2001-12-10 01:27:59 by sebc]
[ghc-hetmet.git] / ghc / includes / Stable.h
index 960ac27..241f42b 100644 (file)
@@ -1,11 +1,18 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stable.h,v 1.4 1999/03/02 19:44:16 sof Exp $
+ * $Id: Stable.h,v 1.10 2001/11/21 10:09:15 simonmar Exp $
  *
- * (c) The GHC Team, 1998-1999
+ * (c) The GHC Team, 1998-2000
  *
- * Stable names and stable pointers
+ * Stable Pointers: A stable pointer is represented as an index into
+ * the stable pointer table in the low BITS_PER_WORD-8 bits with a
+ * weight in the upper 8 bits.
  *
- * ---------------------------------------------------------------------------*/
+ * SUP: StgStablePtr used to be a synonym for StgWord, but stable pointers
+ * are guaranteed to be void* on the C-side, so we have to do some occasional
+ * casting. Size is not a matter, because StgWord is always the same size as
+ * a void*.
+ *
+ * ----------------------------------------------------------------------------*/
 
 /* -----------------------------------------------------------------------------
    External C Interface
 extern StgPtr         deRefStablePtr(StgStablePtr stable_ptr);
 extern void           freeStablePtr(StgStablePtr sp);
 extern StgStablePtr   splitStablePtr(StgStablePtr sp);
+extern StgStablePtr   getStablePtr(StgPtr p);
 
 /* -----------------------------------------------------------------------------
    PRIVATE from here.
    -------------------------------------------------------------------------- */
 
-extern StgStablePtr getStablePtr(StgPtr p);
-
 typedef struct { 
   StgPtr  addr;                        /* Haskell object, free list, or NULL */
-  StgWord weight;              /* used for reference counting */
+  StgPtr  old;                 /* old Haskell object, used during GC */
+  StgWord ref;                 /* used for reference counting */
   StgClosure *sn_obj;          /* the StableName object (or NULL) */
 } snEntry;
 
@@ -35,28 +42,27 @@ extern DLL_IMPORT_RTS 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;
+    ASSERT(stable_ptr_table[(StgWord)sp].ref > 0);
+    return stable_ptr_table[(StgWord)sp].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;
+    StgWord sn = (StgWord)sp;
+    
+    ASSERT(sn < SPT_size
+          && stable_ptr_table[sn].addr != NULL
+          && stable_ptr_table[sn].ref > 0);
+    
+    stable_ptr_table[sn].ref --;
 }
 
 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;
+    stable_ptr_table[(StgWord)sp].ref ++;
+    return sp;
 }
 
 /* No deRefStableName, because the existence of a stable name doesn't