Remove explicit recursion in retainer profiling (fixes #14758)
[ghc.git] / rts / Globals.c
index 2e4b994..c9980d9 100644 (file)
@@ -13,7 +13,7 @@
  *          dynamically loads
  *
  *   libHSghc - a statically-linked ghc has its own copy and so will Core
- *              plugins it dynamically loads (cf CoreMonad.reinitializeGlobals)
+ *              plugins it dynamically loads.
  *
  * ---------------------------------------------------------------------------*/
 
@@ -21,7 +21,7 @@
 #include "Rts.h"
 
 #include "Globals.h"
-#include "Stable.h"
+#include "StablePtr.h"
 
 typedef enum {
     GHCConcSignalSignalHandlerStore,
@@ -33,10 +33,15 @@ typedef enum {
     SystemTimerThreadEventManagerStore,
     SystemTimerThreadIOManagerThreadStore,
     LibHSghcFastStringTable,
+    LibHSghcPersistentLinkerState,
+    LibHSghcInitLinkerDone,
+    LibHSghcGlobalDynFlags,
+    LibHSghcStaticOptions,
+    LibHSghcStaticOptionsReady,
     MaxStoreKey
 } StoreKey;
 
-#ifdef THREADED_RTS
+#if defined(THREADED_RTS)
 Mutex globalStoreLock;
 #endif
 
@@ -45,11 +50,11 @@ static StgStablePtr store[MaxStoreKey];
 void
 initGlobalStore(void)
 {
-    nat i;
+    uint32_t i;
     for (i=0; i < MaxStoreKey; i++) {
         store[i] = 0;
     }
-#ifdef THREADED_RTS
+#if defined(THREADED_RTS)
     initMutex(&globalStoreLock);
 #endif
 }
@@ -57,8 +62,8 @@ initGlobalStore(void)
 void
 exitGlobalStore(void)
 {
-    nat i;
-#ifdef THREADED_RTS
+    uint32_t i;
+#if defined(THREADED_RTS)
     closeMutex(&globalStoreLock);
 #endif
     for (i=0; i < MaxStoreKey; i++) {
@@ -73,70 +78,36 @@ static StgStablePtr getOrSetKey(StoreKey key, StgStablePtr ptr)
 {
     StgStablePtr ret = store[key];
     if(ret==0) {
-#ifdef THREADED_RTS
+#if defined(THREADED_RTS)
         ACQUIRE_LOCK(&globalStoreLock);
         ret = store[key];
         if(ret==0) {
 #endif
             store[key] = ret = ptr;
-#ifdef THREADED_RTS
+#if defined(THREADED_RTS)
         }
         RELEASE_LOCK(&globalStoreLock);
 #endif
     }
     return ret;
-}    
-
-StgStablePtr
-getOrSetGHCConcSignalSignalHandlerStore(StgStablePtr ptr)
-{
-    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);
-}
-
-StgStablePtr
-getOrSetSystemTimerThreadEventManagerStore(StgStablePtr ptr)
-{
-    return getOrSetKey(SystemTimerThreadEventManagerStore,ptr);
-}
-
-StgStablePtr
-getOrSetSystemTimerThreadIOManagerThreadStore(StgStablePtr ptr)
-{
-    return getOrSetKey(SystemTimerThreadIOManagerThreadStore,ptr);
-}
-
-StgStablePtr
-getOrSetLibHSghcFastStringTable(StgStablePtr ptr)
-{
-    return getOrSetKey(LibHSghcFastStringTable,ptr);
-}
+#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)