summaryrefslogtreecommitdiff
path: root/rts/Schedule.h
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2016-08-02 09:55:31 +0100
committerSimon Marlow <marlowsd@gmail.com>2016-08-03 08:07:34 +0100
commit55f5aed756cd5d464942dddcb33e0bd19b05f2a4 (patch)
treef8c0acd76b0945d44cca86946bd638ceee440aa3 /rts/Schedule.h
parent36565a9ba200d40e0be8407e57ada1b4a1c55814 (diff)
downloadhaskell-55f5aed756cd5d464942dddcb33e0bd19b05f2a4.tar.gz
Track the lengths of the thread queues
Summary: Knowing the length of the run queue in O(1) time is useful: for example we don't have to traverse the run queue to know how many threads we have to migrate in schedulePushWork(). Test Plan: validate Reviewers: ezyang, erikd, bgamari, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2437
Diffstat (limited to 'rts/Schedule.h')
-rw-r--r--rts/Schedule.h15
1 files changed, 5 insertions, 10 deletions
diff --git a/rts/Schedule.h b/rts/Schedule.h
index 03a78c9ae9..a8d1fb8b76 100644
--- a/rts/Schedule.h
+++ b/rts/Schedule.h
@@ -139,6 +139,7 @@ appendToRunQueue (Capability *cap, StgTSO *tso)
setTSOPrev(cap, tso, cap->run_queue_tl);
}
cap->run_queue_tl = tso;
+ cap->n_run_queue++;
}
/* Push a thread on the beginning of the run queue.
@@ -159,6 +160,7 @@ pushOnRunQueue (Capability *cap, StgTSO *tso)
if (cap->run_queue_tl == END_TSO_QUEUE) {
cap->run_queue_tl = tso;
}
+ cap->n_run_queue++;
}
/* Pop the first thread off the runnable queue.
@@ -176,6 +178,7 @@ popRunQueue (Capability *cap)
if (cap->run_queue_hd == END_TSO_QUEUE) {
cap->run_queue_tl = END_TSO_QUEUE;
}
+ cap->n_run_queue--;
return t;
}
@@ -214,16 +217,7 @@ emptyQueue (StgTSO *q)
INLINE_HEADER rtsBool
emptyRunQueue(Capability *cap)
{
- return emptyQueue(cap->run_queue_hd);
-}
-
-/* assumes that the queue is not empty; so combine this with
- * an emptyRunQueue check! */
-INLINE_HEADER rtsBool
-singletonRunQueue(Capability *cap)
-{
- ASSERT(!emptyRunQueue(cap));
- return cap->run_queue_hd->_link == END_TSO_QUEUE;
+ return cap->n_run_queue == 0;
}
INLINE_HEADER void
@@ -231,6 +225,7 @@ truncateRunQueue(Capability *cap)
{
cap->run_queue_hd = END_TSO_QUEUE;
cap->run_queue_tl = END_TSO_QUEUE;
+ cap->n_run_queue = 0;
}
#if !defined(THREADED_RTS)