1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1995-2009
5 * The RTS stores some "global" values on behalf of libraries, so that
6 * some libraries can ensure that certain top-level things are shared
7 * even when multiple versions of the library are loaded. e.g. see
8 * Data.Typeable and GHC.Conc.
10 * If/when we switch to a dynamically-linked GHCi, this can all go
11 * away, because there would be just one copy of each library.
13 * ---------------------------------------------------------------------------*/
15 #include "PosixSource.h"
23 GHCConcSignalHandlerStore,
24 GHCConcPendingEventsStore,
25 GHCConcPendingDelaysStore,
26 GHCConcIOManagerThreadStore,
32 Mutex globalStoreLock;
35 StgStablePtr store[MaxStoreKey];
41 for (i=0; i < MaxStoreKey; i++) {
45 initMutex(&globalStoreLock);
54 closeMutex(&globalStoreLock);
56 for (i=0; i < MaxStoreKey; i++) {
58 freeStablePtr(store[i]);
64 static StgStablePtr getOrSetKey(StoreKey key, StgStablePtr ptr)
66 StgStablePtr ret = store[key];
69 ACQUIRE_LOCK(&globalStoreLock);
73 store[key] = ret = ptr;
76 RELEASE_LOCK(&globalStoreLock);
84 getOrSetTypeableStore(StgStablePtr ptr)
86 return getOrSetKey(TypeableStore,ptr);
90 getOrSetGHCConcSignalHandlerStore(StgStablePtr ptr)
92 return getOrSetKey(GHCConcSignalHandlerStore,ptr);
96 getOrSetGHCConcPendingEventsStore(StgStablePtr ptr)
98 return getOrSetKey(GHCConcPendingEventsStore,ptr);
102 getOrSetGHCConcPendingDelaysStore(StgStablePtr ptr)
104 return getOrSetKey(GHCConcPendingDelaysStore,ptr);
108 getOrSetGHCConcIOManagerThreadStore(StgStablePtr ptr)
110 return getOrSetKey(GHCConcIOManagerThreadStore,ptr);
114 getOrSetGHCConcProddingStore(StgStablePtr ptr)
116 return getOrSetKey(GHCConcProddingStore,ptr);