about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--020run.cc8
-rw-r--r--072scheduler.cc31
-rw-r--r--makefile3
3 files changed, 26 insertions, 16 deletions
diff --git a/020run.cc b/020run.cc
index e60e75ac..8f27c820 100644
--- a/020run.cc
+++ b/020run.cc
@@ -57,8 +57,7 @@ void run(recipe_ordinal r) {
 }
 
 void run_current_routine() {
-  while (!Current_routine->completed())  // later layers will modify condition
-  {
+  while (should_continue_running(Current_routine)) {  // beware: later layers modify Current_routine here
     // Running One Instruction
     if (current_instruction().is_label) { ++current_step_index(); continue; }
     trace(Initial_callstack_depth + Trace_stream->callstack_depth, "run") << to_string(current_instruction()) << end();
@@ -101,6 +100,11 @@ void run_current_routine() {
   stop_running_current_routine:;
 }
 
+bool should_continue_running(const routine* current_routine) {
+  assert(current_routine == Current_routine);  // argument passed in just to make caller readable above
+  return !Current_routine->completed();
+}
+
 bool should_copy_ingredients() {
   // End should_copy_ingredients Special-cases
   return true;
diff --git a/072scheduler.cc b/072scheduler.cc
index 31a65b15..5e2ae4fb 100644
--- a/072scheduler.cc
+++ b/072scheduler.cc
@@ -18,12 +18,21 @@ def f2 [
 //: first, add a deadline to run(routine)
 :(before "End Globals")
 int Scheduling_interval = 500;
-//: these changes are ugly and brittle; just close your nose and get through the next few lines
-:(replace "while (!Current_routine->completed())" following "void run_current_routine()")
-int ninstrs = 0;
-while (Current_routine->state == RUNNING && ninstrs < Scheduling_interval)
-:(after "Running One Instruction")
-ninstrs++;
+:(before "End routine Fields")
+int instructions_run_this_scheduling_slice;
+:(before "End routine Constructor")
+instructions_run_this_scheduling_slice = 0;
+:(before "Running One Instruction")
+ ++Current_routine->instructions_run_this_scheduling_slice;
+:(replace{} "bool should_continue_running(const routine* current_routine)")
+bool should_continue_running(const routine* current_routine) {
+  assert(current_routine == Current_routine);  // argument passed in just to make caller readable above
+  return Current_routine->state == RUNNING
+      && Current_routine->instructions_run_this_scheduling_slice < Scheduling_interval;
+}
+:(after "stop_running_current_routine:")
+// Reset instructions_run_this_scheduling_slice
+Current_routine->instructions_run_this_scheduling_slice = 0;
 
 //: now the rest of the scheduler is clean
 
@@ -577,11 +586,11 @@ case LIMIT_TIME: {
 }
 
 :(before "End routine Fields")
-int ninstrs;
+int instructions_run;
 :(before "End routine Constructor")
-ninstrs = 0;
-:(after "stop_running_current_routine:")
-Current_routine->ninstrs += ninstrs;
+instructions_run = 0;
+:(before "Reset instructions_run_this_scheduling_slice")
+Current_routine->instructions_run += Current_routine->instructions_run_this_scheduling_slice;
 :(before "End Primitive Recipe Declarations")
 NUMBER_OF_INSTRUCTIONS,
 :(before "End Primitive Recipe Numbers")
@@ -604,7 +613,7 @@ case NUMBER_OF_INSTRUCTIONS: {
   int result = -1;
   for (int i = 0; i < SIZE(Routines); ++i) {
     if (Routines.at(i)->id == id) {
-      result = Routines.at(i)->ninstrs;
+      result = Routines.at(i)->instructions_run;
       break;
     }
   }
diff --git a/makefile b/makefile
index 0c8cf3f8..7adfaf2d 100644
--- a/makefile
+++ b/makefile
@@ -57,9 +57,6 @@ function_list: mu.cc
 	@# functions start out unindented, have all args on the same line, and end in ') {'
 	@#                                      ignore methods
 	@grep -h "^[^[:space:]#].*) {$$" mu.cc |grep -v ":.*(" |perl -pwe 's/ \{.*/;/' > function_list
-	@# occasionally we need to modify a declaration in a later layer without messing with ugly unbalanced brackets
-	@# assume such functions move the '{' to column 0 of the very next line
-	@grep -v "^#line" mu.cc |grep -B1 "^{" |grep -v "^{" |perl -pwe 's/$$/;/' >> function_list
 
 # auto-generated list of tests to run
 test_list: mu.cc