about summary refs log tree commit diff stats
path: root/cpp/038scheduler
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-23 20:42:17 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-23 20:42:17 -0700
commitc475ccc380c7a17d088ae6fa17060d39c59ec5d1 (patch)
tree945e030ba8a87d7f955cb0dc8585fd1cc19012f3 /cpp/038scheduler
parent785f85f5e6deb494e9836a7f4cea55eb60bc1d9e (diff)
downloadmu-c475ccc380c7a17d088ae6fa17060d39c59ec5d1.tar.gz
1153 - start of scheduler implementation
This first step is just stopping run() after a fixed number of
instructions. But the scheduler layer isn't done yet.
Diffstat (limited to 'cpp/038scheduler')
-rw-r--r--cpp/038scheduler19
1 files changed, 19 insertions, 0 deletions
diff --git a/cpp/038scheduler b/cpp/038scheduler
new file mode 100644
index 00000000..3196795c
--- /dev/null
+++ b/cpp/038scheduler
@@ -0,0 +1,19 @@
+//: Run multiple routines concurrently, without any guarantees on how the
+//: operations in each are interleaved with each other.
+
+:(before "End Globals")
+size_t Scheduling_interval = 500;
+
+//: first, add a deadline to run()
+//: todo: these changes are ugly and brittle
+:(replace{} "void run(recipe_number r)")
+void run(recipe_number r) {
+  run(routine(r), Scheduling_interval);
+}
+:(replace "void run(routine rr)")
+void run(routine rr, size_t time_slice)
+:(replace "while (!done(rr))" following "void run(routine rr, size_t time_slice)")
+size_t ninstrs = 0;
+while (!done(rr) && ninstrs < time_slice)
+:(after "Running One Instruction")
+ninstrs++;