From 70999283156f527c5aea6dee57a3d14989a9903a Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 9 Nov 2022 12:39:47 -0500 Subject: rts: Introduce getNumCapabilities And ensure accesses to n_capabilities are atomic (although with relaxed ordering). This is necessary as RTS API callers may concurrently call into the RTS without holding a capability. --- rts/Capability.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'rts/Capability.c') diff --git a/rts/Capability.c b/rts/Capability.c index afe21fcb46..bf20d991e8 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -131,7 +131,7 @@ findSpark (Capability *cap) retry = true; } - if (n_capabilities == 1) { return NULL; } // makes no sense... + if (getNumCapabilities() == 1) { return NULL; } // makes no sense... debugTrace(DEBUG_sched, "cap %d: Trying to steal work from other capabilities", @@ -139,7 +139,7 @@ findSpark (Capability *cap) /* visit cap.s 0..n-1 in sequence until a theft succeeds. We could start at a random place instead of 0 as well. */ - for ( i=0 ; i < n_capabilities ; i++ ) { + for ( i=0 ; i < getNumCapabilities() ; i++ ) { robbed = capabilities[i]; if (cap == robbed) // ourselves... continue; @@ -182,7 +182,7 @@ anySparks (void) { uint32_t i; - for (i=0; i < n_capabilities; i++) { + for (i=0; i < getNumCapabilities(); i++) { if (!emptySparkPoolCap(capabilities[i])) { return true; } @@ -464,7 +464,7 @@ moreCapabilities (uint32_t from USED_IF_THREADS, uint32_t to USED_IF_THREADS) void contextSwitchAllCapabilities(void) { uint32_t i; - for (i=0; i < n_capabilities; i++) { + for (i=0; i < getNumCapabilities(); i++) { contextSwitchCapability(capabilities[i], true); } } @@ -472,7 +472,7 @@ void contextSwitchAllCapabilities(void) void interruptAllCapabilities(void) { uint32_t i; - for (i=0; i < n_capabilities; i++) { + for (i=0; i < getNumCapabilities(); i++) { interruptCapability(capabilities[i]); } } @@ -1249,7 +1249,7 @@ void shutdownCapabilities(Task *task, bool safe) { uint32_t i; - for (i=0; i < n_capabilities; i++) { + for (i=0; i < getNumCapabilities(); i++) { ASSERT(task->incall->tso == NULL); shutdownCapability(capabilities[i], task, safe); } @@ -1276,7 +1276,7 @@ freeCapabilities (void) { #if defined(THREADED_RTS) uint32_t i; - for (i=0; i < n_capabilities; i++) { + for (i=0; i < getNumCapabilities(); i++) { freeCapability(capabilities[i]); if (capabilities[i] != &MainCapability) stgFree(capabilities[i]); @@ -1332,7 +1332,7 @@ void markCapabilities (evac_fn evac, void *user) { uint32_t n; - for (n = 0; n < n_capabilities; n++) { + for (n = 0; n < getNumCapabilities(); n++) { markCapability(evac, user, capabilities[n], false); } } @@ -1344,7 +1344,7 @@ bool checkSparkCountInvariant (void) StgWord64 remaining = 0; uint32_t i; - for (i = 0; i < n_capabilities; i++) { + for (i = 0; i < getNumCapabilities(); i++) { sparks.created += capabilities[i]->spark_stats.created; sparks.dud += capabilities[i]->spark_stats.dud; sparks.overflowed+= capabilities[i]->spark_stats.overflowed; -- cgit v1.2.1