about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-10 06:02:36 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-10 06:02:36 -0700
commit134dad7c4bbabb4770727240b150d566aa041567 (patch)
treef3d4bbe57724ead899048554a3157a569b01e856
parentcf9af278782a0ac030a249c5f5c95c0868956123 (diff)
downloadmu-134dad7c4bbabb4770727240b150d566aa041567.tar.gz
1321 - *finally*, fixed the chessboard sluggishness
-rw-r--r--038scheduler.cc17
-rw-r--r--039wait.cc28
-rw-r--r--074keyboard.mu2
-rw-r--r--chessboard.mu3
4 files changed, 47 insertions, 3 deletions
diff --git a/038scheduler.cc b/038scheduler.cc
index c67dfdae..99ced920 100644
--- a/038scheduler.cc
+++ b/038scheduler.cc
@@ -325,6 +325,23 @@ case RESTART: {
 }
 
 :(before "End Primitive Recipe Declarations")
+STOP,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["stop"] = STOP;
+:(before "End Primitive Recipe Implementations")
+case STOP: {
+  assert(ingredients.at(0).size() == 1);  // routine id must be scalar
+  index_t id = ingredients.at(0).at(0);
+  for (index_t i = 0; i < Routines.size(); ++i) {
+    if (Routines.at(i)->id == id) {
+      Routines.at(i)->state = COMPLETED;
+      break;
+    }
+  }
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
 _DUMP_ROUTINES,
 :(before "End Primitive Recipe Numbers")
 Recipe_number["$dump-routines"] = _DUMP_ROUTINES;
diff --git a/039wait.cc b/039wait.cc
index 0bd0ab38..5d4acebd 100644
--- a/039wait.cc
+++ b/039wait.cc
@@ -120,3 +120,31 @@ for (index_t i = 0; i < Routines.size(); ++i) {
     }
   }
 }
+
+:(before "End Primitive Recipe Declarations")
+SWITCH,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["switch"] = SWITCH;
+:(before "End Primitive Recipe Implementations")
+case SWITCH: {
+  index_t id = some_other_running_routine();
+  if (id) {
+    assert(id != Current_routine->id);
+    cerr << "waiting on " << id << " from " << Current_routine->id << '\n';
+    Current_routine->state = WAITING;
+    Current_routine->waiting_on_routine = id;
+  }
+  break;
+}
+
+:(code)
+index_t some_other_running_routine() {
+  for (index_t i = 0; i < Routines.size(); ++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;
+}
diff --git a/074keyboard.mu b/074keyboard.mu
index d61fff15..13068c12 100644
--- a/074keyboard.mu
+++ b/074keyboard.mu
@@ -35,6 +35,8 @@ recipe read-key [
     idx:address:integer/deref <- add idx:address:integer/deref, 1:literal
     reply c:character, 1:literal/found, x:address:keyboard/same-as-ingredient:0
   }
+  # real keyboard input is infrequent; avoid polling it too much
+  switch
   c:character, found?:boolean <- read-key-from-keyboard
   reply c:character, found?:boolean, x:address:keyboard/same-as-ingredient:0
 ]
diff --git a/chessboard.mu b/chessboard.mu
index 7c196d6c..3481c19b 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -489,9 +489,6 @@ scenario making-a-move [
 #?   $print c:character
 #? ]
 
-# todo:
-#   problem with buffering
-#   some way of closing channels
 recipe chessboard [
   default-space:address:array:location <- new location:type, 30:literal
   board:address:array:address:array:character <- initial-position