Use https links in user-facing startup and error messages
[ghc.git] / rts / Globals.c
index 15b1013..c9980d9 100644 (file)
@@ -7,27 +7,54 @@
  * even when multiple versions of the library are loaded.  e.g. see
  * Data.Typeable and GHC.Conc.
  *
+ * How are multiple versions of a library loaded? Examples:
+ *
+ *   base - a statically-linked ghci has its own copy, so might libraries it
+ *          dynamically loads
+ *
+ *   libHSghc - a statically-linked ghc has its own copy and so will Core
+ *              plugins it dynamically loads.
+ *
  * ---------------------------------------------------------------------------*/
 
 #include "PosixSource.h"
 #include "Rts.h"
 
 #include "Globals.h"
-#include "Stable.h"
+#include "StablePtr.h"
 
-static StgStablePtr typeableStore      = 0;
-static StgStablePtr signalHandlerStore = 0;
+typedef enum {
+    GHCConcSignalSignalHandlerStore,
+    GHCConcWindowsPendingDelaysStore,
+    GHCConcWindowsIOManagerThreadStore,
+    GHCConcWindowsProddingStore,
+    SystemEventThreadEventManagerStore,
+    SystemEventThreadIOManagerThreadStore,
+    SystemTimerThreadEventManagerStore,
+    SystemTimerThreadIOManagerThreadStore,
+    LibHSghcFastStringTable,
+    LibHSghcPersistentLinkerState,
+    LibHSghcInitLinkerDone,
+    LibHSghcGlobalDynFlags,
+    LibHSghcStaticOptions,
+    LibHSghcStaticOptionsReady,
+    MaxStoreKey
+} StoreKey;
 
-#ifdef THREADED_RTS
+#if defined(THREADED_RTS)
 Mutex globalStoreLock;
 #endif
 
+static StgStablePtr store[MaxStoreKey];
+
 void
 initGlobalStore(void)
 {
-    typeableStore      = 0;
-    signalHandlerStore = 0;
-#ifdef THREADED_RTS
+    uint32_t i;
+    for (i=0; i < MaxStoreKey; i++) {
+        store[i] = 0;
+    }
+#if defined(THREADED_RTS)
     initMutex(&globalStoreLock);
 #endif
 }
@@ -35,53 +62,52 @@ initGlobalStore(void)
 void
 exitGlobalStore(void)
 {
-#ifdef THREADED_RTS
+    uint32_t i;
+#if defined(THREADED_RTS)
     closeMutex(&globalStoreLock);
 #endif
-    if(typeableStore!=0) {
-        freeStablePtr((StgStablePtr)typeableStore);
-        typeableStore=0;
-    }
-    if(signalHandlerStore!=0) {
-        freeStablePtr((StgStablePtr)signalHandlerStore);
-        signalHandlerStore=0;
-    }
-}
-
-StgStablePtr
-getOrSetTypeableStore(StgStablePtr ptr)
-{
-    StgStablePtr ret = typeableStore;
-    if(ret==0) {
-#ifdef THREADED_RTS
-        ACQUIRE_LOCK(&globalStoreLock);
-        ret=typeableStore;
-        if(ret==0) {
-#endif
-            typeableStore = ret = ptr;
-#ifdef THREADED_RTS
+    for (i=0; i < MaxStoreKey; i++) {
+        if (store[i] != 0) {
+            freeStablePtr(store[i]);
+            store[i] = 0;
         }
-        RELEASE_LOCK(&globalStoreLock);
-#endif
     }
-    return ret;
 }
 
-StgStablePtr
-getOrSetSignalHandlerStore(StgStablePtr ptr)
+static StgStablePtr getOrSetKey(StoreKey key, StgStablePtr ptr)
 {
-    StgStablePtr ret = signalHandlerStore;
+    StgStablePtr ret = store[key];
     if(ret==0) {
-#ifdef THREADED_RTS
+#if defined(THREADED_RTS)
         ACQUIRE_LOCK(&globalStoreLock);
-        ret=signalHandlerStore;
+        ret = store[key];
         if(ret==0) {
 #endif
-            signalHandlerStore = ret = ptr;
-#ifdef THREADED_RTS
+            store[key] = ret = ptr;
+#if defined(THREADED_RTS)
         }
         RELEASE_LOCK(&globalStoreLock);
 #endif
     }
     return ret;
 }
+
+#define mkStoreAccessor(name) \
+    StgStablePtr \
+    getOrSet##name(StgStablePtr ptr) \
+    { return getOrSetKey(name, ptr); }
+
+mkStoreAccessor(GHCConcSignalSignalHandlerStore)
+mkStoreAccessor(GHCConcWindowsPendingDelaysStore)
+mkStoreAccessor(GHCConcWindowsIOManagerThreadStore)
+mkStoreAccessor(GHCConcWindowsProddingStore)
+mkStoreAccessor(SystemEventThreadEventManagerStore)
+mkStoreAccessor(SystemEventThreadIOManagerThreadStore)
+mkStoreAccessor(SystemTimerThreadEventManagerStore)
+mkStoreAccessor(SystemTimerThreadIOManagerThreadStore)
+mkStoreAccessor(LibHSghcFastStringTable)
+mkStoreAccessor(LibHSghcPersistentLinkerState)
+mkStoreAccessor(LibHSghcInitLinkerDone)
+mkStoreAccessor(LibHSghcGlobalDynFlags)
+mkStoreAccessor(LibHSghcStaticOptions)
+mkStoreAccessor(LibHSghcStaticOptionsReady)