From 78aa13019dc856f45d1efbe89ba12491fc4e31de Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Tue, 15 Mar 2016 06:25:53 +0000 Subject: [PATCH] Don't return to the mutator if there's an emergency. Clarifying "more time" and what we do if there's isn't. Copied from Perforce Change: 190050 ServerID: perforce.ravenbrook.com --- mps/code/policy.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/mps/code/policy.c b/mps/code/policy.c index d0d0a72dfde..b82954bbbe4 100644 --- a/mps/code/policy.c +++ b/mps/code/policy.c @@ -369,31 +369,38 @@ Bool PolicyPoll(Arena arena) Bool PolicyPollAgain(Arena arena, Clock start, Bool moreWork, Work tracedWork) { + Bool moreTime; + Globals globals; + double nextPollThreshold; + AVERT(Arena, arena); UNUSED(tracedWork); - /* Is there more work to do and more time to do it in? */ - if ((moreWork || ArenaEmergency(arena)) - && (ClockNow() - start) < ArenaPauseTime(arena) * ClocksPerSec()) - { + if (ArenaEmergency(arena)) return TRUE; + + /* Is there more work to do and more time to do it in? */ + moreTime = (ClockNow() - start) < ArenaPauseTime(arena) * ClocksPerSec(); + if (moreWork && moreTime) + return TRUE; + + /* We're not going to do more work now, so calculate when to come back. */ + + globals = ArenaGlobals(arena); + + if (moreWork) { + /* We did one quantum of work; consume one unit of 'time'. */ + nextPollThreshold = globals->pollThreshold + ArenaPollALLOCTIME; } else { - Globals globals = ArenaGlobals(arena); - double nextPollThreshold; - - if (moreWork) { - /* We did one quantum of work; consume one unit of 'time'. */ - nextPollThreshold = globals->pollThreshold + ArenaPollALLOCTIME; - } else { - /* No more work to do. Sleep until NOW + a bit. */ - nextPollThreshold = globals->fillMutatorSize + ArenaPollALLOCTIME; - } - - /* Advance pollThreshold; check: enough precision? */ - AVER(nextPollThreshold > globals->pollThreshold); - globals->pollThreshold = nextPollThreshold; - return FALSE; + /* No more work to do. Sleep until NOW + a bit. */ + nextPollThreshold = globals->fillMutatorSize + ArenaPollALLOCTIME; } + + /* Advance pollThreshold; check: enough precision? */ + AVER(nextPollThreshold > globals->pollThreshold); + globals->pollThreshold = nextPollThreshold; + + return FALSE; }