From 666191cba363d91c6beb8a23b26d48a7f726e4ad Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 18 Oct 2016 10:14:14 -0700 Subject: 3517 - don't block routines in 'switch' The notion of blocking is just to enable certain kinds of tests. We should never be using it in production code. --- 073wait.cc | 58 +++++++++++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/073wait.cc b/073wait.cc index 26fb07a0..0f6266eb 100644 --- a/073wait.cc +++ b/073wait.cc @@ -372,12 +372,30 @@ for (int i = 0; i < SIZE(Routines); ++i) { } } +//: yield voluntarily to let some other routine run + +:(before "End Primitive Recipe Declarations") +SWITCH, +:(before "End Primitive Recipe Numbers") +put(Recipe_ordinal, "switch", SWITCH); +:(before "End Primitive Recipe Checks") +case SWITCH: { + break; +} +:(before "End Primitive Recipe Implementations") +case SWITCH: { + ++current_step_index(); + goto stop_running_current_routine; +} + +//:(scenario switch_preempts_current_routine) + + //:: helpers for manipulating routines in tests //: //: Managing arbitrary scenarios requires the ability to: -//: a) stop the current routine (`switch`) -//: b) restart a routine (`restart`) -//: c) tell when a routine is blocked +//: a) check if a routine is blocked +//: b) restart a blocked routine (`restart`) //: //: A routine is blocked either if it's waiting or if it explicitly signals //: that it's blocked (even as it periodically wakes up and polls for some @@ -501,40 +519,6 @@ for (int i = 0; i < SIZE(Routines); ++i) { } } -//: yield voluntarily to let some other routine run - -:(before "End Primitive Recipe Declarations") -SWITCH, -:(before "End Primitive Recipe Numbers") -put(Recipe_ordinal, "switch", SWITCH); -:(before "End Primitive Recipe Checks") -case SWITCH: { - break; -} -//: pick another RUNNING routine at random and wait for it to get a chance -//: there might be a better implementation than this -:(before "End Primitive Recipe Implementations") -case SWITCH: { - int id = some_other_running_routine(); - if (id) { - assert(id != Current_routine->id); - Current_routine->state = WAITING; - Current_routine->waiting_on_routine_to_block = id; - } - break; -} -:(code) -int some_other_running_routine() { - for (int i = 0; i < SIZE(Routines); ++i) { - if (i == Current_routine_index) continue; - assert(Routines.at(i) != Current_routine); - assert(Routines.at(i)->id != Current_routine->id); - if (Routines.at(i)->state == RUNNING) - return Routines.at(i)->id; - } - return 0; -} - //: helper for restarting blocking routines in tests :(before "End Primitive Recipe Declarations") -- cgit 1.4.1-2-gfad0