X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FGlobals.c;h=7b8967f685e4d635e8382d29bf389559cd95bcd3;hb=7d9eb2e45b4a9ff4cb053b1ec37602be88528b62;hp=a0d0788335c14f4e75fe656de9ba075c62197a6f;hpb=1c4738ba866893b3b5c7c9952e9a1bf48e2aa055;p=ghc-hetmet.git diff --git a/rts/Globals.c b/rts/Globals.c index a0d0788..7b8967f 100644 --- a/rts/Globals.c +++ b/rts/Globals.c @@ -7,23 +7,41 @@ * 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 @@ -32,53 +50,75 @@ initGlobalStore(void) 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); }