about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-21 15:07:33 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-21 15:07:33 -0800
commit913c4b5f15b9ded3e26a05320e1874a4ecaadec5 (patch)
treec40b41bdfc8530c92c7708a48bb538344a064a0f
parenta384ea314c14bab2c1043a2e5f07a6ebb9052f70 (diff)
downloadmu-913c4b5f15b9ded3e26a05320e1874a4ecaadec5.tar.gz
280 - waking up sleeping routines
Tests still hanging at some point.
-rw-r--r--mu.arc12
-rw-r--r--mu.arc.t40
2 files changed, 47 insertions, 5 deletions
diff --git a/mu.arc b/mu.arc
index 59c4338c..420201f7 100644
--- a/mu.arc
+++ b/mu.arc
@@ -213,6 +213,13 @@
         (enq routine* running-routines*)
       :else
         (push routine* completed-routines*))
+  (each (routine _) canon.sleeping-routines*
+    (when (> curr-cycle* rep.routine!sleep.1)
+      (trace "schedule" "waking up " top.routine!fn-name)
+      (wipe sleeping-routines*.routine)  ; do this before modifying routine
+      (wipe rep.routine!sleep)
+      (++ pc.routine)
+      (enq routine running-routines*)))
   )
 
 ;?   (while (or (~empty running-routines*)
@@ -226,11 +233,6 @@
 ;?                 ;else
 ;?                   (aand (m rep.routine!sleep)
 ;?                         (~is it 0)))
-;?         (trace "schedule" "waking up " top.routine!fn-name)
-;?         (wipe sleeping-routines*.routine)  ; before modifying routine below
-;?         (wipe rep.routine!sleep)
-;?         (++ pc.routine)  ; complete the sleep instruction
-;?         (enq routine running-routines*)))
 ;? ;?     (prn running-routines*)
 ;?     (detect-deadlock)
 ;?     (when (empty running-routines*)
diff --git a/mu.arc.t b/mu.arc.t
index 6d4536e3..d023d2f9 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1721,6 +1721,46 @@
   ))
 
 (reset)
+(new-trace "scheduler-sleep")
+(add-fns
+  '((f1
+      ((1 integer) <- copy (3 literal)))
+    (f2
+      ((2 integer) <- copy (4 literal)))))
+; add one baseline routine to run (empty running-routines* handled below)
+(enq make-routine!f1 running-routines*)
+(assert (is 1 len.running-routines*))
+; sleeping routine
+(let routine make-routine!f2
+  (= rep.routine!sleep '(literal 23))
+  (set sleeping-routines*.routine))
+; not yet time for it to wake up
+(= curr-cycle* 23)
+(update-scheduler-state)
+(if (~is 1 len.running-routines*)
+  (prn "F - scheduler lets routines sleep"))
+
+(reset)
+(new-trace "scheduler-wakeup")
+(add-fns
+  '((f1
+      ((1 integer) <- copy (3 literal)))
+    (f2
+      ((2 integer) <- copy (4 literal)))))
+; add one baseline routine to run (empty running-routines* handled below)
+(enq make-routine!f1 running-routines*)
+(assert (is 1 len.running-routines*))
+; sleeping routine
+(let routine make-routine!f2
+  (= rep.routine!sleep '(literal 23))
+  (set sleeping-routines*.routine))
+; time for it to wake up
+(= curr-cycle* 24)
+(update-scheduler-state)
+(if (~is 2 len.running-routines*)
+  (prn "F - scheduler wakes up sleeping routines at the right time"))
+
+(reset)
 (new-trace "sleep")
 (add-fns
   '((f1