vfs: reduce memory use by embedding sync.Cond
This commit is contained in:
parent
821e084f28
commit
e749bc58f4
4 changed files with 10 additions and 10 deletions
|
@ -20,7 +20,7 @@ type ReadFileHandle struct {
|
|||
baseHandle
|
||||
done func(ctx context.Context, err error)
|
||||
mu sync.Mutex
|
||||
cond *sync.Cond // cond lock for out of sequence reads
|
||||
cond sync.Cond // cond lock for out of sequence reads
|
||||
closed bool // set if handle has been closed
|
||||
r *accounting.Account
|
||||
readCalled bool // set if read has been called
|
||||
|
@ -63,7 +63,7 @@ func newReadFileHandle(f *File) (*ReadFileHandle, error) {
|
|||
size: nonNegative(o.Size()),
|
||||
sizeUnknown: o.Size() < 0,
|
||||
}
|
||||
fh.cond = sync.NewCond(&fh.mu)
|
||||
fh.cond = sync.Cond{L: &fh.mu}
|
||||
return fh, nil
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ func (fh *ReadFileHandle) readAt(p []byte, off int64) (n int, err error) {
|
|||
maxBuf = len(p)
|
||||
}
|
||||
if gap := off - fh.offset; gap > 0 && gap < int64(8*maxBuf) {
|
||||
waitSequential("read", fh.remote, fh.cond, fh.file.VFS().Opt.ReadWait, &fh.offset, off)
|
||||
waitSequential("read", fh.remote, &fh.cond, fh.file.VFS().Opt.ReadWait, &fh.offset, off)
|
||||
}
|
||||
doSeek := off != fh.offset
|
||||
if doSeek && fh.noSeek {
|
||||
|
|
|
@ -52,7 +52,7 @@ type Cache struct {
|
|||
avFn AddVirtualFn // if set, can be called to add dir entries
|
||||
|
||||
mu sync.Mutex // protects the following variables
|
||||
cond *sync.Cond // cond lock for synchronous cache cleaning
|
||||
cond sync.Cond // cond lock for synchronous cache cleaning
|
||||
item map[string]*Item // files/directories in the cache
|
||||
errItems map[string]error // items in error state
|
||||
used int64 // total size of files in the cache
|
||||
|
@ -139,7 +139,7 @@ func New(ctx context.Context, fremote fs.Fs, opt *vfscommon.Options, avFn AddVir
|
|||
|
||||
// Create a channel for cleaner to be kicked upon out of space con
|
||||
c.kick = make(chan struct{}, 1)
|
||||
c.cond = sync.NewCond(&c.mu)
|
||||
c.cond = sync.Cond{L: &c.mu}
|
||||
|
||||
go c.cleaner(ctx)
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ type Item struct {
|
|||
// read only
|
||||
c *Cache // cache this is part of
|
||||
mu sync.Mutex // protect the variables
|
||||
cond *sync.Cond // synchronize with cache cleaner
|
||||
cond sync.Cond // synchronize with cache cleaner
|
||||
name string // name in the VFS
|
||||
opens int // number of times file is open
|
||||
downloaders *downloaders.Downloaders // a record of the downloaders in action - may be nil
|
||||
|
@ -138,7 +138,7 @@ func newItem(c *Cache, name string) (item *Item) {
|
|||
ATime: now,
|
||||
},
|
||||
}
|
||||
item.cond = sync.NewCond(&item.mu)
|
||||
item.cond = sync.Cond{L: &item.mu}
|
||||
// check the cache file exists
|
||||
osPath := c.toOSPath(name)
|
||||
fi, statErr := os.Stat(osPath)
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
type WriteFileHandle struct {
|
||||
baseHandle
|
||||
mu sync.Mutex
|
||||
cond *sync.Cond // cond lock for out of sequence writes
|
||||
cond sync.Cond // cond lock for out of sequence writes
|
||||
closed bool // set if handle has been closed
|
||||
remote string
|
||||
pipeWriter *io.PipeWriter
|
||||
|
@ -43,7 +43,7 @@ func newWriteFileHandle(d *Dir, f *File, remote string, flags int) (*WriteFileHa
|
|||
result: make(chan error, 1),
|
||||
file: f,
|
||||
}
|
||||
fh.cond = sync.NewCond(&fh.mu)
|
||||
fh.cond = sync.Cond{L: &fh.mu}
|
||||
fh.file.addWriter(fh)
|
||||
return fh, nil
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func (fh *WriteFileHandle) writeAt(p []byte, off int64) (n int, err error) {
|
|||
return 0, ECLOSED
|
||||
}
|
||||
if fh.offset != off {
|
||||
waitSequential("write", fh.remote, fh.cond, fh.file.VFS().Opt.WriteWait, &fh.offset, off)
|
||||
waitSequential("write", fh.remote, &fh.cond, fh.file.VFS().Opt.WriteWait, &fh.offset, off)
|
||||
}
|
||||
if fh.offset != off {
|
||||
fs.Errorf(fh.remote, "WriteFileHandle.Write: can't seek in file without --vfs-cache-mode >= writes")
|
||||
|
|
Loading…
Reference in a new issue