about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-22 19:50:21 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-22 19:50:21 -0800
commitdcfe7891164fd6cc223c78b91d88f183fe577a20 (patch)
tree03d6f144718b4048e2e847ea1b0b6010cdc3fe25
parentd5bb1bfb19ebfe1e852c0e76b991feaf61c6436f (diff)
downloadmu-dcfe7891164fd6cc223c78b91d88f183fe577a20.tar.gz
297
-rw-r--r--mu.arc8
1 files changed, 8 insertions, 0 deletions
diff --git a/mu.arc b/mu.arc
index 97fa06d3..988c711f 100644
--- a/mu.arc
+++ b/mu.arc
@@ -945,17 +945,21 @@
     ((watch boolean-address deref) <- copy (nil literal))
     (sleep (watch boolean-address deref))
   }
+  ; store val
   ((q tagged-value-array-address) <- get (chan channel-address deref) (circular-buffer offset))
   ((free integer-address) <- get-address (chan channel-address deref) (first-free offset))
   ((dest tagged-value-address) <- index-address (q tagged-value-array-address deref) (free integer-address deref))
   ((dest tagged-value-address deref) <- copy (val tagged-value))
+  ; increment free
   ((free integer-address deref) <- add (free integer-address deref) (1 literal))
   { begin
+    ; wrap free around to 0 if necessary
     ((qlen integer) <- len (q tagged-value-array-address deref))
     ((remaining? boolean) <- lt (free integer-address deref) (qlen integer))
     (break-if (remaining? boolean))
     ((free integer-address deref) <- copy (0 literal))
   }
+  ; set 'write-watch' in case the reader was blocked on it
   ((watch boolean-address) <- get-address (chan channel-address deref) (write-watch offset))
   ((watch boolean-address deref) <- copy (t literal))
   (reply (chan channel-address deref)))
@@ -973,16 +977,20 @@
     ((watch boolean-address deref) <- copy (nil literal))
     (sleep (watch boolean-address deref))
   }
+  ; read result
   ((full integer-address) <- get-address (chan channel-address deref) (first-full offset))
   ((q tagged-value-array-address) <- get (chan channel-address deref) (circular-buffer offset))
   ((result tagged-value) <- index (q tagged-value-array-address deref) (full integer-address deref))
+  ; increment full
   ((full integer-address deref) <- add (full integer-address deref) (1 literal))
   { begin
+    ; wrap full around to 0 if necessary
     ((qlen integer) <- len (q tagged-value-array-address deref))
     ((remaining? boolean) <- lt (full integer-address deref) (qlen integer))
     (break-if (remaining? boolean))
     ((full integer-address deref) <- copy (0 literal))
   }
+  ; set 'read-watch' in case the writer was blocked on it
   ((watch boolean-address) <- get-address (chan channel-address deref) (read-watch offset))
   ((watch boolean-address deref) <- copy (t literal))
   (reply (result tagged-value) (chan channel-address deref)))