[project @ 2003-03-25 17:24:30 by sof]
[ghc-hetmet.git] / ghc / rts / Stable.c
index 5cf9c28..e9c6181 100644 (file)
@@ -1,12 +1,15 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stable.c,v 1.20 2002/04/09 12:56:36 simonmar Exp $
+ * $Id: Stable.c,v 1.24 2003/01/28 17:05:43 simonmar Exp $
  *
- * (c) The GHC Team, 1998-1999
+ * (c) The GHC Team, 1998-2002
  *
  * Stable names and stable pointers.
  *
  * ---------------------------------------------------------------------------*/
 
+// Make static versions of inline functions in Stable.h:
+#define RTS_STABLE_C
+
 #include "PosixSource.h"
 #include "Rts.h"
 #include "Hash.h"
   make sure we can still find the object.
 */
 
-snEntry *stable_ptr_table;
-snEntry *stable_ptr_free;
+snEntry *stable_ptr_table = NULL;
+static snEntry *stable_ptr_free = NULL;
 
-unsigned int SPT_size;
+static unsigned int SPT_size = 0;
 
 /* This hash table maps Haskell objects to stable names, so that every
  * call to lookupStableName on a given object will return the same
@@ -125,7 +128,7 @@ unsigned int SPT_size;
  * to the weight stored in the table entry.
  * */
 
-HashTable *addrToStableHash;
+static HashTable *addrToStableHash = NULL;
 
 #define INIT_SPT_SIZE 64
 
@@ -147,12 +150,9 @@ initFreeList(snEntry *table, nat n, snEntry *free)
 void
 initStablePtrTable(void)
 {
-  /* the table will be allocated the first time makeStablePtr is
-   * called */
-  stable_ptr_table = NULL;
-  stable_ptr_free  = NULL;
-  addrToStableHash = NULL;
-  SPT_size = 0;
+    // Nothing to do:
+    // the table will be allocated the first time makeStablePtr is
+    // called, and we want the table to persist through multiple inits.
 }
 
 /*
@@ -245,7 +245,7 @@ freeStablePtr(StgStablePtr sp)
     // If this entry has no StableName attached, then just free it
     // immediately.  This is important; it might be a while before the
     // next major GC which actually collects the entry.
-    if (sn->sn_obj == NULL) {
+    if (sn->sn_obj == NULL && sn->ref == 0) {
        freeStableName(sn);
     }
 }