[Git][ghc/ghc][wip/ghc-debug] Introduce rts_isPaused() (#18405)

Sven Tennie gitlab at gitlab.haskell.org
Sun Jun 28 14:41:43 UTC 2020



Sven Tennie pushed to branch wip/ghc-debug at Glasgow Haskell Compiler / GHC


Commits:
bf6cd82c by Sven Tennie at 2020-06-28T16:40:31+02:00
Introduce rts_isPaused() (#18405)

Some operations are only save when the RTS is paused. This predicate
helps to make such checks.

- - - - -


4 changed files:

- includes/RtsAPI.h
- rts/Heap.c
- rts/RtsAPI.c
- testsuite/tests/rts/ghc-debug/pause_and_unpause_thread.c


Changes:

=====================================
includes/RtsAPI.h
=====================================
@@ -504,6 +504,9 @@ RtsPaused rts_pause (void);
 // (i.e. myTask() must stay the same).
 void rts_unpause (RtsPaused paused);
 
+// Tells the current state of the RTS regarding rts_pause() and rts_unpause().
+bool rts_isPaused(void);
+
 // List all live threads. Must be done while RTS is paused (see rts_pause()).
 typedef void (*ListThreadsCb)(void *user, StgTSO *);
 void rts_listThreads(ListThreadsCb cb, void *user);


=====================================
rts/Heap.c
=====================================
@@ -247,6 +247,13 @@ static StgWord collect_pointers(StgClosure *closure, StgWord size, StgClosure *p
 }
 
 StgArrBytes *heap_view_closurePtrsAsWords(Capability *cap, StgClosure *closure) {
+    if(!rts_isPaused()){
+        errorBelch("Warning: "
+            "The RTS must be paused (see rts_pause()) to inspect it's heap!");
+
+        return NULL;
+    }
+
     ASSERT(LOOKS_LIKE_CLOSURE_PTR(closure));
 
     StgWord size = heap_view_closureSize(closure);


=====================================
rts/RtsAPI.c
=====================================
@@ -672,6 +672,12 @@ void rts_unpause (RtsPaused paused)
     freeTask(paused.pausing_task);
 }
 
+// Tells the current state of the RTS regarding rts_pause() and rts_unpause().
+bool rts_isPaused(void)
+{
+    return rts_paused;
+}
+
 // Call cb for all StgTSOs. *user is a user defined payload to cb. It's not
 // used by the RTS.
 // rts_listThreads should only be called when the RTS is paused, i.e. rts_pause
@@ -732,6 +738,13 @@ void rts_unpause (RtsPaused paused STG_UNUSED)
                "multithreaded RTS.");
 }
 
+bool rts_isPaused(void)
+{
+    errorBelch("Warning: (Un-) Pausing the RTS is only possible for "
+               "multithreaded RTS.");
+    return false;
+}
+
 
 void rts_listThreads(ListThreadsCb cb STG_UNUSED, void *user STG_UNUSED)
 {


=====================================
testsuite/tests/rts/ghc-debug/pause_and_unpause_thread.c
=====================================
@@ -12,6 +12,11 @@ struct PauseTimestamps timestamps = {0, 0};
 void* pauseAndUnpause_thread(void* unused){
     RtsPaused r_paused = rts_pause();
 
+    if(!rts_isPaused()) {
+        errorBelch("Expected the RTS to be paused.");
+        exit(1);
+    }
+
     timestamps.begin = time(NULL);
     sleep(5);
     timestamps.end = time(NULL);



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf6cd82c46e18e7ce0642ff20ab0df928a433759

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf6cd82c46e18e7ce0642ff20ab0df928a433759
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200628/9c7ac113/attachment-0001.html>


More information about the ghc-commits mailing list