* even when multiple versions of the library are loaded. e.g. see
* Data.Typeable and GHC.Conc.
*
+ * If/when we switch to a dynamically-linked GHCi, this can all go
+ * away, because there would be just one copy of each library.
+ *
* ---------------------------------------------------------------------------*/
+#include "PosixSource.h"
#include "Rts.h"
-#include "RtsGlobals.h"
-static StgStablePtr typeableStore = 0;
-static StgStablePtr signalHandlerStore = 0;
+#include "Globals.h"
+#include "Stable.h"
+
+typedef enum {
+ TypeableStore,
+ GHCConcSignalSignalHandlerStore,
+ GHCConcWindowsPendingDelaysStore,
+ GHCConcWindowsIOManagerThreadStore,
+ GHCConcWindowsProddingStore,
+ SystemEventThreadEventManagerStore,
+ SystemEventThreadIOManagerThreadStore,
+ MaxStoreKey
+} StoreKey;
#ifdef THREADED_RTS
Mutex globalStoreLock;
#endif
+static StgStablePtr store[MaxStoreKey];
+
void
initGlobalStore(void)
{
- typeableStore = 0;
- signalHandlerStore = 0;
+ nat i;
+ for (i=0; i < MaxStoreKey; i++) {
+ store[i] = 0;
+ }
#ifdef THREADED_RTS
initMutex(&globalStoreLock);
#endif
void
exitGlobalStore(void)
{
+ nat i;
#ifdef THREADED_RTS
closeMutex(&globalStoreLock);
#endif
- if(typeableStore!=0) {
- freeStablePtr((StgStablePtr)typeableStore);
- typeableStore=0;
- }
- if(signalHandlerStore!=0) {
- freeStablePtr((StgStablePtr)signalHandlerStore);
- signalHandlerStore=0;
+ for (i=0; i < MaxStoreKey; i++) {
+ if (store[i] != 0) {
+ freeStablePtr(store[i]);
+ store[i] = 0;
+ }
}
}
-StgStablePtr
-getOrSetTypeableStore(StgStablePtr ptr)
+static StgStablePtr getOrSetKey(StoreKey key, StgStablePtr ptr)
{
- StgStablePtr ret = typeableStore;
+ StgStablePtr ret = store[key];
if(ret==0) {
#ifdef THREADED_RTS
ACQUIRE_LOCK(&globalStoreLock);
- ret=typeableStore;
+ ret = store[key];
if(ret==0) {
#endif
- typeableStore = ret = ptr;
+ store[key] = ret = ptr;
#ifdef THREADED_RTS
}
RELEASE_LOCK(&globalStoreLock);
#endif
}
return ret;
+}
+
+
+StgStablePtr
+getOrSetTypeableStore(StgStablePtr ptr)
+{
+ return getOrSetKey(TypeableStore,ptr);
}
StgStablePtr
-getOrSetSignalHandlerStore(StgStablePtr ptr)
+getOrSetGHCConcSignalSignalHandlerStore(StgStablePtr ptr)
{
- StgStablePtr ret = signalHandlerStore;
- if(ret==0) {
-#ifdef THREADED_RTS
- ACQUIRE_LOCK(&globalStoreLock);
- ret=signalHandlerStore;
- if(ret==0) {
-#endif
- signalHandlerStore = ret = ptr;
-#ifdef THREADED_RTS
- }
- RELEASE_LOCK(&globalStoreLock);
-#endif
- }
- return ret;
+ return getOrSetKey(GHCConcSignalSignalHandlerStore,ptr);
+}
+
+StgStablePtr
+getOrSetGHCConcWindowsPendingDelaysStore(StgStablePtr ptr)
+{
+ return getOrSetKey(GHCConcWindowsPendingDelaysStore,ptr);
+}
+
+StgStablePtr
+getOrSetGHCConcWindowsIOManagerThreadStore(StgStablePtr ptr)
+{
+ return getOrSetKey(GHCConcWindowsIOManagerThreadStore,ptr);
+}
+
+StgStablePtr
+getOrSetGHCConcWindowsProddingStore(StgStablePtr ptr)
+{
+ return getOrSetKey(GHCConcWindowsProddingStore,ptr);
+}
+
+StgStablePtr
+getOrSetSystemEventThreadEventManagerStore(StgStablePtr ptr)
+{
+ return getOrSetKey(SystemEventThreadEventManagerStore,ptr);
+}
+
+StgStablePtr
+getOrSetSystemEventThreadIOManagerThreadStore(StgStablePtr ptr)
+{
+ return getOrSetKey(SystemEventThreadIOManagerThreadStore,ptr);
}