about summary refs log tree commit diff stats
path: root/cpp/038scheduler.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-05 17:54:46 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-05 17:54:46 -0700
commit82ceda30ad6fb32382bb6d0565c75fe6a1a01b9f (patch)
tree91b52744240749efdacb87a86455e753dab31e84 /cpp/038scheduler.cc
parent6d17ef493bbec78ebda37e50e0cc8ce21fd9f46b (diff)
downloadmu-82ceda30ad6fb32382bb6d0565c75fe6a1a01b9f.tar.gz
1267 - 'routine-state' can use the provided routine id
Diffstat (limited to 'cpp/038scheduler.cc')
-rw-r--r--cpp/038scheduler.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/cpp/038scheduler.cc b/cpp/038scheduler.cc
index dbefe556..d387bae5 100644
--- a/cpp/038scheduler.cc
+++ b/cpp/038scheduler.cc
@@ -195,3 +195,38 @@ recipe f1 [
 ]
 +schedule: f1
 -run: idle
+
+//:: 'routine-state' can tell if a given routine id is running
+
+:(scenario routine_state_test)
+% Scheduling_interval = 2;
+recipe f1 [
+  1:integer/child-id <- start-running f2:recipe
+  12:integer <- copy 0:literal  # race condition since we don't care about location 12
+  # thanks to Scheduling_interval, f2's one instruction runs in between here and completes
+  2:integer/state <- routine-state 1:integer/child-id
+]
+recipe f2 [
+  12:integer <- copy 0:literal
+  # trying to run a second instruction marks routine as completed
+]
+# recipe f2 should be in state COMPLETED
++mem: storing 1 in location 2
+
+:(before "End Primitive Recipe Declarations")
+ROUTINE_STATE,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["routine-state"] = ROUTINE_STATE;
+:(before "End Primitive Recipe Implementations")
+case ROUTINE_STATE: {
+  vector<long long int> result;
+  index_t id = read_memory(current_instruction().ingredients[0])[0];
+  for (index_t i = 0; i < Routines.size(); ++i) {
+    if (Routines[i]->id == id) {
+      result.push_back(Routines[i]->state);
+      write_memory(current_instruction().products[0], result);
+      break;
+    }
+  }
+  break;
+}