Protect StablPtr dereference with the StaticPtr table lock.
authorFacundo Domínguez <facundo.dominguez@tweag.io>
Thu, 1 Sep 2016 19:31:26 +0000 (16:31 -0300)
committerFacundo Domínguez <facundo.dominguez@tweag.io>
Fri, 2 Sep 2016 12:59:18 +0000 (09:59 -0300)
Summary: Also comment on the need to use stgMallocBytes in StaticPtrTable.c.

Test Plan: ./validate

Reviewers: erikd, austin, bgamari, simonmar

Reviewed By: simonmar

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2506

rts/StaticPtrTable.c

index f7fe066..57ade5b 100644 (file)
@@ -43,6 +43,9 @@ void hs_spt_insert(StgWord64 key[2],void *spe_closure) {
 #endif
   }
 
+  // Cannot remove this indirection yet because getStablePtr()
+  // might return NULL, in which case hs_spt_lookup() returns NULL
+  // instead of the actual closure pointer.
   StgStablePtr * entry = stgMallocBytes( sizeof(StgStablePtr)
                                        , "hs_spt_insert: entry"
                                        );
@@ -72,8 +75,8 @@ StgPtr hs_spt_lookup(StgWord64 key[2]) {
   if (spt) {
     ACQUIRE_LOCK(&spt_lock);
     const StgStablePtr * entry = lookupHashTable(spt, (StgWord)key);
-    RELEASE_LOCK(&spt_lock);
     const StgPtr ret = entry ? deRefStablePtr(*entry) : NULL;
+    RELEASE_LOCK(&spt_lock);
     return ret;
   } else
     return NULL;