#include "Storage.h"
#include "RtsAPI.h"
#include "RtsFlags.h"
+#include "OSThreads.h"
/* Comment from ADR's implementation in old RTS:
static unsigned int SPT_size = 0;
+#ifdef THREADED_RTS
+static Mutex stable_mutex;
+#endif
+
/* This hash table maps Haskell objects to stable names, so that every
* call to lookupStableName on a given object will return the same
* stable name.
//
// Also, getStablePtr is now called from __attribute__((constructor))
// functions, so initialising things here wouldn't work anyway.
+#ifdef THREADED_RTS
+ initMutex(&stable_mutex);
+#endif
}
/*
return q;
}
-StgWord
-lookupStableName(StgPtr p)
+static StgWord
+lookupStableName_(StgPtr p)
{
StgWord sn;
void* sn_tmp;
}
}
+StgWord
+lookupStableName(StgPtr p)
+{
+ StgWord res;
+ ACQUIRE_LOCK(&stable_mutex);
+ res = lookupStableName_(p);
+ RELEASE_LOCK(&stable_mutex);
+ return res;
+}
+
STATIC_INLINE void
freeStableName(snEntry *sn)
{
{
StgWord sn;
- sn = lookupStableName(p);
+ ACQUIRE_LOCK(&stable_mutex);
+ sn = lookupStableName_(p);
stable_ptr_table[sn].ref++;
+ RELEASE_LOCK(&stable_mutex);
return (StgStablePtr)(sn);
}
void
freeStablePtr(StgStablePtr sp)
{
- snEntry *sn = &stable_ptr_table[(StgWord)sp];
+ snEntry *sn;
+
+ ACQUIRE_LOCK(&stable_mutex);
+
+ sn = &stable_ptr_table[(StgWord)sp];
ASSERT((StgWord)sp < SPT_size && sn->addr != NULL && sn->ref > 0);
if (sn->sn_obj == NULL && sn->ref == 0) {
freeStableName(sn);
}
+
+ RELEASE_LOCK(&stable_mutex);
}
void