about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--mu.arc23
-rw-r--r--mu.arc.t19
2 files changed, 37 insertions, 5 deletions
diff --git a/mu.arc b/mu.arc
index fe9e3b91..b3474962 100644
--- a/mu.arc
+++ b/mu.arc
@@ -194,14 +194,23 @@
              (~empty sleeping-routines*))
     (point continue
     (each (routine _) sleeping-routines*
-      (awhen (> curr-cycle* rep.routine!sleep.0)
+;?       (prn "DDD " rep.routine!sleep)
+      (awhen (case rep.routine!sleep.1
+                literal
+                  (> curr-cycle* rep.routine!sleep.0)
+                ;else
+                  (aand (m rep.routine!sleep)
+;?                   (aand (m (prn2 "CCC " rep.routine!sleep))
+                        (~is it 0)))
         (trace "schedule" "waking up " top.routine!fn-name)
+;?         (prn "BBB " routine)
         (wipe sleeping-routines*.routine)  ; before modifying routine below
         (wipe rep.routine!sleep)
         (++ pc.routine)  ; complete the sleep instruction
         (enq routine running-routines*)))
     (when (empty running-routines*)
       ; ensure forward progress
+;?       (prn sleeping-routines*)
       (trace "schedule" "skipping cycle " curr-cycle*)
       (++ curr-cycle*)
       (continue))
@@ -210,6 +219,7 @@
     (routine-mark:run-for-time-slice scheduling-interval*)
     (if rep.routine*!sleep
           (do (trace "schedule" "pushing " top.routine*!fn-name " to sleep queue")
+;?               (prn "AAA " routine*)
               (set sleeping-routines*.routine*))
         (~empty routine*)
           (enq routine* running-routines*)
@@ -487,10 +497,13 @@
                   (assert (m arg.0))
                 sleep
                   (let operand arg.0
-                    (assert (is ty.operand 'literal) "sleep can only handle literal deltas")
-                    (let delay v.operand
-                      (trace "run" "sleeping until " (+ curr-cycle* delay))
-                      (= rep.routine*!sleep `(,(+ curr-cycle* delay) literal)))
+                    (assert (~pos 'deref metadata.operand)
+                            "sleep doesn't support indirect addressing yet")
+                    (if (is ty.operand 'literal)
+                      (let delay v.operand
+                        (trace "run" "sleeping until " (+ curr-cycle* delay))
+                        (= rep.routine*!sleep `(,(+ curr-cycle* delay) literal)))
+                      (= rep.routine*!sleep operand))
                     ((abort-routine*)))
 
                 ; text interaction
diff --git a/mu.arc.t b/mu.arc.t
index 4050a6aa..9e6ea769 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1722,6 +1722,25 @@
     ("run" "f1 2")
   ))
 
+(reset)
+(new-trace "sleep-location")
+(add-fns
+  '((f1
+      ; waits for memory location 1 to be set, before computing its successor
+      ((1 integer) <- copy (0 literal))
+      (sleep (1 integer))
+      ((2 integer) <- add (1 integer) (1 literal)))
+    (f2
+      (sleep (30 literal))
+      ((1 integer) <- copy (3 literal)))))  ; set to value
+;? (= dump-trace* (obj whitelist '("run" "schedule")))
+(= scheduling-interval* 1)
+(run 'f1 'f2)
+;? (prn canon.memory*)
+(if (~is memory*.2 4)  ; successor of value
+  (prn "F - scheduler handles routines blocking on a memory location"))
+;? (quit)
+
 ; The scheduler needs to keep track of the call stack for each routine.
 ; Eventually we'll want to save this information in mu's address space itself,
 ; along with the types array, the magic buffers for args and oargs, and so on.