summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-10-20 15:51:08 -0400
committerBen Gamari <ben@smart-cactus.org>2022-11-16 21:46:49 -0500
commitd73379a5a3b2d6381ccd578d843aae7ba36799cd (patch)
treefe0f5ef45dcff22a7e7cb748e098f6c5338b33c5
parent2975b366fefde0b366ecda60749137a99f472ce6 (diff)
downloadhaskell-d73379a5a3b2d6381ccd578d843aae7ba36799cd.tar.gz
Assert capability ownership
-rw-r--r--rts/Capability.c4
-rw-r--r--rts/Capability.h2
-rw-r--r--rts/ward.config5
3 files changed, 10 insertions, 1 deletions
diff --git a/rts/Capability.c b/rts/Capability.c
index 7d44b0ec38..194184b101 100644
--- a/rts/Capability.c
+++ b/rts/Capability.c
@@ -494,6 +494,7 @@ void interruptAllCapabilities(void)
#if defined(THREADED_RTS)
WARD_NEED(capability_lock_held)
+WARD_GRANT(TASK_OWNS_CAPABILITY(task, cap))
static void
giveCapabilityToTask (Capability *cap USED_IF_DEBUG, Task *task)
{
@@ -777,6 +778,7 @@ static Capability * waitForWorkerCapability (Task *task)
#if defined(THREADED_RTS)
+WARD_GRANT(TASK_OWNS_CAPABILITY(task, *return))
static Capability * waitForReturnCapability (Task *task)
{
Capability *cap;
@@ -882,6 +884,7 @@ static Capability * find_capability_for_task(const Task * task)
*
* ------------------------------------------------------------------------- */
+WARD_GRANT(TASK_OWNS_CAPABILITY(task, *cap))
void waitForCapability (Capability **pCap, Task *task)
{
#if !defined(THREADED_RTS)
@@ -956,6 +959,7 @@ void waitForCapability (Capability **pCap, Task *task)
/* See Note [GC livelock] in Schedule.c for why we have gcAllowed
and return the bool */
+WARD_REVOKE(TASK_OWNS_CAPABILITY(task, *cap))
bool /* Did we GC? */
yieldCapability
( Capability** pCap // [in/out] Task's owned capability. Set to the
diff --git a/rts/Capability.h b/rts/Capability.h
index 78b7b6f083..ba19e3130d 100644
--- a/rts/Capability.h
+++ b/rts/Capability.h
@@ -386,6 +386,8 @@ void markCapabilities (evac_fn evac, void *user);
void traverseSparkQueues (evac_fn evac, void *user);
+#define TASK_OWNS_CAPABILITY(task, cap) task_owns_capability
+
WARD_GRANT(capability_lock_held)
INLINE_HEADER void
acquire_capability_lock(Capability *cap) {
diff --git a/rts/ward.config b/rts/ward.config
index cd34be6a1b..6585b1914e 100644
--- a/rts/ward.config
+++ b/rts/ward.config
@@ -14,7 +14,10 @@ gc_block_alloc_spin_held "gc_block_alloc_spin is held"
stable_ptr_lock_held "the stable pointer lock is held";
-task_owns_capability "the current thread's Task owns the Capability";
+// N.B. Use the TASK_OWNS_CAPABILITY macro instead of this capability directly where
+// possible to clarify which Capability and which Task we are talking about.
+task_owns_capability "a Task owns the Capability";
+
capability_lock_held "the Capability's lock is held";
.enforce "Storage.c";