about summary refs log tree commit diff stats
path: root/072channel.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-04-15 09:25:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-04-15 09:25:52 -0700
commitd31d70b60e6f136ad99274051ccbd494c4e6d058 (patch)
tree132b9ab9cb6dd667b4a257cd143183227fac1564 /072channel.mu
parent2cc42dcec9809efd12de279a7cc4641db691e0a8 (diff)
downloadmu-d31d70b60e6f136ad99274051ccbd494c4e6d058.tar.gz
2835 - continue replacing 'get-address' with 'put'
I have a tack now for issue 2 of 2829 (dealing with wait-for-location):
have get-address and index-address return a type that can't be looked
up. That way the worst that can happen with an address pointing to a
freed location is a routine that randomly hangs and starts working
again. And even that won't happen if you disallow transferring the new
type across routines in ingredients or channels, just like I plan to do
with 'address:shared'.
Diffstat (limited to '072channel.mu')
-rw-r--r--072channel.mu35
1 files changed, 21 insertions, 14 deletions
diff --git a/072channel.mu b/072channel.mu
index 2633b80a..25956af9 100644
--- a/072channel.mu
+++ b/072channel.mu
@@ -70,18 +70,21 @@ def write out:address:shared:sink:_elem, val:_elem -> out:address:shared:sink:_e
   }
   # store val
   circular-buffer:address:shared:array:_elem <- get *chan, data:offset
-  free:address:number <- get-address *chan, first-free:offset
-  dest:address:_elem <- index-address *circular-buffer, *free
+  free:number <- get *chan, first-free:offset
+  dest:address:_elem <- index-address *circular-buffer, free
   *dest <- copy val
   # mark its slot as filled
-  *free <- add *free, 1
+  # todo: clear the slot itself
+  free <- add free, 1
   {
     # wrap free around to 0 if necessary
     len:number <- length *circular-buffer
-    at-end?:boolean <- greater-or-equal *free, len
+    at-end?:boolean <- greater-or-equal free, len
     break-unless at-end?
-    *free <- copy 0
+    free <- copy 0
   }
+  # write back
+  put *chan, first-free:offset, free
 ]
 
 def read in:address:shared:source:_elem -> result:_elem, in:address:shared:source:_elem [
@@ -95,19 +98,22 @@ def read in:address:shared:source:_elem -> result:_elem, in:address:shared:sourc
     free-address:address:number <- get-address *chan, first-free:offset
     wait-for-location free-address
   }
-  # read result
-  full:address:number <- get-address *chan, first-full:offset
+  # pull result off
+  full:number <- get *chan, first-full:offset
   circular-buffer:address:shared:array:_elem <- get *chan, data:offset
-  result <- index *circular-buffer, *full
+  result <- index *circular-buffer, full
   # mark its slot as empty
-  *full <- add *full, 1
+  # todo: clear the slot itself
+  full <- add full, 1
   {
     # wrap full around to 0 if necessary
     len:number <- length *circular-buffer
-    at-end?:boolean <- greater-or-equal *full, len
+    at-end?:boolean <- greater-or-equal full, len
     break-unless at-end?
-    *full <- copy 0
+    full <- copy 0
   }
+  # write back
+  put *chan, first-full:offset, full
 ]
 
 def clear in:address:shared:source:_elem -> in:address:shared:source:_elem [
@@ -302,10 +308,11 @@ def buffer-lines in:address:shared:source:character, buffered-out:address:shared
         break-unless backspace?
         # drop previous character
         {
-          buffer-length:address:number <- get-address *line, length:offset
-          buffer-empty?:boolean <- equal *buffer-length, 0
+          buffer-length:number <- get *line, length:offset
+          buffer-empty?:boolean <- equal buffer-length, 0
           break-if buffer-empty?
-          *buffer-length <- subtract *buffer-length, 1
+          buffer-length <- subtract buffer-length, 1
+          put *line, length:offset, buffer-length
         }
         # and don't append this one
         loop +next-character:label