about summary refs log tree commit diff stats
path: root/088file.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-29 17:06:48 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-29 17:06:48 -0700
commitef69c56c82e85e83014605f501110697d81bcdc1 (patch)
tree7d1794a21701db7ecac84f747d165470daba7fc2 /088file.mu
parent358aa35d306571511a4a8027d7033ffe37e8812d (diff)
downloadmu-ef69c56c82e85e83014605f501110697d81bcdc1.tar.gz
3608 - concurrent writes to fake file system
Diffstat (limited to '088file.mu')
-rw-r--r--088file.mu6
1 files changed, 5 insertions, 1 deletions
diff --git a/088file.mu b/088file.mu
index 3c31e66f..de374f1f 100644
--- a/088file.mu
+++ b/088file.mu
@@ -2,6 +2,7 @@
 # are thus easier to test.
 
 container resources [
+  lock:bool
   data:&:@:resource
 ]
 
@@ -84,7 +85,6 @@ def start-writing resources:&:resources, filename:text -> sink:&:sink:char, rout
   {
     break-unless resources
     # fake file system
-    # beware: doesn't support multiple concurrent writes yet
     routine-id <- start-running transmit-to-fake-file resources, filename, source
     reply
   }
@@ -109,6 +109,8 @@ def transmit-to-file file:num, source:&:source:char -> source:&:source:char [
 def transmit-to-fake-file resources:&:resources, filename:text, source:&:source:char -> resources:&:resources, source:&:source:char [
   local-scope
   load-ingredients
+  lock:location <- get-location *resources, lock:offset
+  wait-for-reset-then-set lock
   # compute new file contents
   buf:&:buffer <- new-buffer 30
   {
@@ -133,6 +135,7 @@ def transmit-to-fake-file resources:&:resources, filename:text, source:&:source:
     found?:bool <- equal filename, curr-filename
     loop-unless found?
     put-index *data, i, new-resource
+    reset lock
     reply
   }
   # if file didn't already exist, make room for it
@@ -149,4 +152,5 @@ def transmit-to-fake-file resources:&:resources, filename:text, source:&:source:
   }
   # write new file
   put-index *new-data, len, new-resource
+  reset lock
 ]