about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-06 10:22:33 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-06 10:22:33 -0800
commit7d743c6061d9c65bf172fcfa8a3354d70aa98c7f (patch)
tree16823719035bedc6d6abb9f6185fc7c3892c5fbd
parent1f75e48cef3ca9dfd37eea3c5e86a0c18ac7a6dc (diff)
downloadmu-7d743c6061d9c65bf172fcfa8a3354d70aa98c7f.tar.gz
231
-rw-r--r--mu.arc69
1 files changed, 35 insertions, 34 deletions
diff --git a/mu.arc b/mu.arc
index d450c77c..06fd2f0b 100644
--- a/mu.arc
+++ b/mu.arc
@@ -130,7 +130,41 @@
   (each (name . body) fns
     (= function*.name (convert-names:convert-braces body))))
 
-;; running mu
+;; managing concurrent routines
+(on-init
+  (= running-routines* (queue))
+  (= completed-routines* (queue))
+  (= routine* nil)
+  (= abort-routine* (parameter nil)))
+
+; like arc's 'point' but you can also call ((abort-routine*)) in nested calls
+(mac routine-mark body
+  (w/uniq (g p)
+    `(ccc (fn (,g)
+            (parameterize abort-routine* (fn ((o ,p)) (,g ,p))
+              ,@body)))))
+
+(def run fn-names
+  (ret result 0
+    (each it fn-names
+      (enq make-routine.it running-routines*))
+    ; simple round-robin scheduler
+    (while (~empty running-routines*)
+      (= routine* deq.running-routines*)
+      (trace "schedule" top.routine*!fn-name)
+      (whenlet insts-run (routine-mark:run-for-time-slice scheduling-interval*)
+        (= result (+ result insts-run)))
+      (if (~empty routine*)
+        (enq routine* running-routines*)
+        (enq-limit routine* completed-routines*)))))
+
+(def die (msg)
+  (= rep.routine*!error msg)
+  (= rep.routine*!stack-trace rep.routine*!call-stack)
+  (wipe rep.routine*!call-stack)
+  ((abort-routine*)))
+
+;; running a single routine
 (mac v (operand)  ; for value
   `(,operand 0))
 
@@ -314,39 +348,6 @@
 (mac results (routine)  ; assignable
   `((((rep ,routine) 'call-stack) 0) 'results))
 
-(on-init
-  (= running-routines* (queue))
-  (= completed-routines* (queue))
-  (= routine* nil)
-  (= abort-routine* (parameter nil)))
-
-; like arc's 'point' but you can also call ((abort-routine*)) in nested calls
-(mac routine-mark body
-  (w/uniq (g p)
-    `(ccc (fn (,g)
-            (parameterize abort-routine* (fn ((o ,p)) (,g ,p))
-              ,@body)))))
-
-(def run fn-names
-  (ret result 0
-    (each it fn-names
-      (enq make-routine.it running-routines*))
-    ; simple round-robin scheduler
-    (while (~empty running-routines*)
-      (= routine* deq.running-routines*)
-      (trace "schedule" top.routine*!fn-name)
-      (whenlet insts-run (routine-mark:run-for-time-slice scheduling-interval*)
-        (= result (+ result insts-run)))
-      (if (~empty routine*)
-        (enq routine* running-routines*)
-        (enq-limit routine* completed-routines*)))))
-
-(def die (msg)
-  (= rep.routine*!error msg)
-  (= rep.routine*!stack-trace rep.routine*!call-stack)
-  (wipe rep.routine*!call-stack)
-  ((abort-routine*)))
-
 ($:require "charterm/main.rkt")
 
 (def run-for-time-slice (time-slice)