summaryrefslogtreecommitdiff
path: root/rts/Schedule.h
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-09-30 16:04:52 +0000
committerBen Gamari <ben@smart-cactus.org>2020-10-24 21:00:38 -0400
commit56778ab38eeb9fd683250a57c228f3821a444811 (patch)
treea80208f7f0fb1a3d5ec35e0307addce8285b0ed1 /rts/Schedule.h
parentd4a87779dc691a4db876817e01ba237655768d77 (diff)
downloadhaskell-56778ab38eeb9fd683250a57c228f3821a444811.tar.gz
rts/Schedule: Eliminate data races in run queue management
Diffstat (limited to 'rts/Schedule.h')
-rw-r--r--rts/Schedule.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/rts/Schedule.h b/rts/Schedule.h
index a550a6763a..4c692842e7 100644
--- a/rts/Schedule.h
+++ b/rts/Schedule.h
@@ -184,10 +184,13 @@ popRunQueue (Capability *cap)
StgTSO *t = cap->run_queue_hd;
ASSERT(t != END_TSO_QUEUE);
cap->run_queue_hd = t->_link;
- if (t->_link != END_TSO_QUEUE) {
- t->_link->block_info.prev = END_TSO_QUEUE;
+
+ StgTSO *link = RELAXED_LOAD(&t->_link);
+ if (link != END_TSO_QUEUE) {
+ link->block_info.prev = END_TSO_QUEUE;
}
- t->_link = END_TSO_QUEUE; // no write barrier req'd
+ RELAXED_STORE(&t->_link, END_TSO_QUEUE); // no write barrier req'd
+
if (cap->run_queue_hd == END_TSO_QUEUE) {
cap->run_queue_tl = END_TSO_QUEUE;
}
@@ -230,12 +233,18 @@ emptyQueue (StgTSO *q)
INLINE_HEADER bool
emptyRunQueue(Capability *cap)
{
+ // Can only be called by the task owning the capability.
+ TSAN_ANNOTATE_BENIGN_RACE(&cap->n_run_queue, "emptyRunQueue");
return cap->n_run_queue == 0;
}
INLINE_HEADER void
truncateRunQueue(Capability *cap)
{
+ // Can only be called by the task owning the capability.
+ TSAN_ANNOTATE_BENIGN_RACE(&cap->run_queue_hd, "truncateRunQueue");
+ TSAN_ANNOTATE_BENIGN_RACE(&cap->run_queue_tl, "truncateRunQueue");
+ TSAN_ANNOTATE_BENIGN_RACE(&cap->n_run_queue, "truncateRunQueue");
cap->run_queue_hd = END_TSO_QUEUE;
cap->run_queue_tl = END_TSO_QUEUE;
cap->n_run_queue = 0;