summaryrefslogtreecommitdiff
path: root/rts/include
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-10-26 13:08:39 -0400
committerBen Gamari <ben@smart-cactus.org>2022-08-06 11:48:50 -0400
commitaa818a9f83308d0742e8f8c91cb9878182dacce5 (patch)
tree48089b58289212cfdaef065ad7cc21b77c8beaaa /rts/include
parent7267cd52fb0b06479b9ceea2dc4700d949a1d75b (diff)
downloadhaskell-aa818a9f83308d0742e8f8c91cb9878182dacce5.tar.gz
Add primop to list threads
A user came to #ghc yesterday wondering how best to check whether they were leaking threads. We ended up using the eventlog but it seems to me like it would be generally useful if Haskell programs could query their own threads.
Diffstat (limited to 'rts/include')
-rw-r--r--rts/include/rts/Threads.h4
-rw-r--r--rts/include/rts/storage/Closures.h2
-rw-r--r--rts/include/rts/storage/GC.h5
-rw-r--r--rts/include/stg/MiscClosures.h1
4 files changed, 9 insertions, 3 deletions
diff --git a/rts/include/rts/Threads.h b/rts/include/rts/Threads.h
index 46a20089a7..83ffce9238 100644
--- a/rts/include/rts/Threads.h
+++ b/rts/include/rts/Threads.h
@@ -53,6 +53,10 @@ StgThreadID rts_getThreadId (StgPtr tso);
void rts_enableThreadAllocationLimit (StgPtr tso);
void rts_disableThreadAllocationLimit (StgPtr tso);
+// Forward declarations, defined in Closures.h
+struct _StgMutArrPtrs;
+struct _StgMutArrPtrs *listThreads (Capability *cap);
+
#if !defined(mingw32_HOST_OS)
pid_t forkProcess (HsStablePtr *entry);
#else
diff --git a/rts/include/rts/storage/Closures.h b/rts/include/rts/storage/Closures.h
index 84971d92a6..c1de80aa4d 100644
--- a/rts/include/rts/storage/Closures.h
+++ b/rts/include/rts/storage/Closures.h
@@ -206,7 +206,7 @@ typedef struct {
// Closure types: MUT_ARR_PTRS_CLEAN, MUT_ARR_PTRS_DIRTY,
// MUT_ARR_PTRS_FROZEN_DIRTY, MUT_ARR_PTRS_FROZEN_CLEAN, MUT_VAR_CLEAN,
// MUT_VAR_DIRTY
-typedef struct {
+typedef struct _StgMutArrPtrs {
StgHeader header;
StgWord ptrs;
StgWord size; // ptrs plus card table
diff --git a/rts/include/rts/storage/GC.h b/rts/include/rts/storage/GC.h
index 478503aaee..77f7f38d9a 100644
--- a/rts/include/rts/storage/GC.h
+++ b/rts/include/rts/storage/GC.h
@@ -116,8 +116,9 @@ typedef struct generation_ {
//
memcount max_blocks;
- StgTSO * threads; // threads in this gen
- // linked via global_link
+ StgTSO * threads; // threads in this generation.
+ // linked via global_link.
+ // protected by sched_mutex except during GC.
StgWeak * weak_ptr_list; // weak pointers in this gen
struct generation_ *to; // destination gen for live objects
diff --git a/rts/include/stg/MiscClosures.h b/rts/include/stg/MiscClosures.h
index c1f9d3e94d..6b784306fb 100644
--- a/rts/include/stg/MiscClosures.h
+++ b/rts/include/stg/MiscClosures.h
@@ -533,6 +533,7 @@ RTS_FUN_DECL(stg_myThreadIdzh);
RTS_FUN_DECL(stg_labelThreadzh);
RTS_FUN_DECL(stg_isCurrentThreadBoundzh);
RTS_FUN_DECL(stg_threadStatuszh);
+RTS_FUN_DECL(stg_listThreadszh);
RTS_FUN_DECL(stg_mkWeakzh);
RTS_FUN_DECL(stg_mkWeakNoFinalizzerzh);