From 8010a8342dbb7fdc229552965d215ec2bb65bbd5 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 4 May 2015 21:53:39 +1000 Subject: [PATCH] InterruptFS.WaitForReadInFlight --- samples/interruptfs/interrupt_fs.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/samples/interruptfs/interrupt_fs.go b/samples/interruptfs/interrupt_fs.go index 2e14f5d..f990fbd 100644 --- a/samples/interruptfs/interrupt_fs.go +++ b/samples/interruptfs/interrupt_fs.go @@ -17,6 +17,7 @@ package interruptfs import ( "fmt" "os" + "sync" "github.com/jacobsa/fuse" "github.com/jacobsa/fuse/fuseops" @@ -42,10 +43,16 @@ var fooAttrs = fuseops.InodeAttributes{ // Must be created with New. type InterruptFS struct { fuseutil.NotImplementedFileSystem + + mu sync.Mutex + readInFlight bool + readInFlightChanged sync.Cond } func New() (fs *InterruptFS) { fs = &InterruptFS{} + fs.readInFlightChanged.L = &fs.mu + return } @@ -53,11 +60,16 @@ func New() (fs *InterruptFS) { // Public interface //////////////////////////////////////////////////////////////////////// -// Block until there is a read in flight. +// Block until the first read is received. // // LOCKS_EXCLUDED(fs.mu) func (fs *InterruptFS) WaitForReadInFlight() { - panic("TODO") + fs.mu.Lock() + defer fs.mu.Unlock() + + for !fs.readInFlight { + fs.readInFlightChanged.Wait() + } } ////////////////////////////////////////////////////////////////////////