Kill the mutexes, don't seem to be required

This commit is contained in:
Alex Yatskov 2015-07-06 14:16:03 +09:00
parent 51c0dee7b3
commit 1ba41be529
3 changed files with 3 additions and 43 deletions

23
dir.go
View File

@ -26,7 +26,6 @@ import (
"errors"
"os"
"path"
"sync"
"bazil.org/fuse"
"bazil.org/fuse/fs"
@ -43,20 +42,16 @@ type verDir struct {
node *verNode
inode uint64
parent *verDir
mutex sync.Mutex
}
func newVerDir(node *verNode, parent *verDir) *verDir {
dirs := make(map[string]*verDir)
files := make(map[string]*verFile)
return &verDir{dirs, files, node, allocInode(), parent, sync.Mutex{}}
return &verDir{dirs, files, node, allocInode(), parent}
}
func (vd *verDir) version() error {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if vd.node.flags&NodeFlagNew == NodeFlagNew {
return nil
}
@ -85,9 +80,7 @@ func (vd *verDir) createDir(name string) (*verDir, error) {
node := newVerNode(childPath, vd.node.ver, nil, NodeFlagDir|NodeFlagNew)
dir := newVerDir(node, vd)
vd.mutex.Lock()
vd.dirs[name] = dir
vd.mutex.Unlock()
node.ver.meta.createNode(node.path)
return dir, nil
@ -107,18 +100,13 @@ func (vd *verDir) createFile(name string, flags fuse.OpenFlags, mode os.FileMode
return nil, nil, 0, err
}
vd.mutex.Lock()
vd.files[name] = file
vd.mutex.Unlock()
node.ver.meta.createNode(node.path)
return file, handle, id, nil
}
func (vd *verDir) removeDir(name string) error {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if err := vd.version(); err != nil {
return err
}
@ -137,9 +125,6 @@ func (vd *verDir) removeDir(name string) error {
}
func (vd *verDir) removeFile(name string) error {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if err := vd.version(); err != nil {
return err
}
@ -208,9 +193,6 @@ func (vd *verDir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
// NodeRequestLookuper
func (vd *verDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
vd.mutex.Lock()
defer vd.mutex.Unlock()
if dir, ok := vd.dirs[name]; ok {
return dir, nil
}
@ -224,9 +206,6 @@ func (vd *verDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
// HandleReadDirAller
func (vd *verDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
vd.mutex.Lock()
defer vd.mutex.Unlock()
entries := []fuse.Dirent{{Inode: vd.inode, Name: ".", Type: fuse.DT_Dir}}
if vd.parent != nil {
entry := fuse.Dirent{Inode: vd.parent.inode, Name: "..", Type: fuse.DT_Dir}

13
file.go
View File

@ -24,7 +24,6 @@ package main
import (
"os"
"sync"
"bazil.org/fuse"
"bazil.org/fuse/fs"
@ -42,17 +41,13 @@ type verFile struct {
inode uint64
parent *verDir
handles handleMap
mutex sync.Mutex
}
func newVerFile(node *verNode, parent *verDir) *verFile {
return &verFile{node, allocInode(), parent, make(handleMap), sync.Mutex{}}
return &verFile{node, allocInode(), parent, make(handleMap)}
}
func (vf *verFile) version() error {
vf.mutex.Lock()
defer vf.mutex.Unlock()
if vf.node.flags&NodeFlagNew == NodeFlagNew {
return nil
}
@ -85,17 +80,13 @@ func (vf *verFile) open(flags fuse.OpenFlags, mode os.FileMode) (*verFileHandle,
id := allocHandleId()
verHandle := &verFileHandle{vf, path, handle}
vf.mutex.Lock()
vf.handles[id] = verHandle
vf.mutex.Unlock()
return verHandle, id, nil
}
func (vf *verFile) release(handle fuse.HandleID) {
vf.mutex.Lock()
delete(vf.handles, handle)
vf.mutex.Unlock()
}
// Node
@ -128,8 +119,6 @@ func (vf *verFile) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.O
// NodeFsyncer
func (vf *verFile) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
vf.mutex.Lock()
defer vf.mutex.Unlock()
return vf.handles[req.Handle].handle.Sync()
}

10
meta.go
View File

@ -28,7 +28,6 @@ import (
"os"
"path"
"strings"
"sync"
)
//
@ -43,11 +42,10 @@ type verMeta struct {
path string
deleted map[string]bool
modified bool
mutex sync.Mutex
}
func newVerMeta(path string) (*verMeta, error) {
meta := &verMeta{path, make(map[string]bool), false, sync.Mutex{}}
meta := &verMeta{path, make(map[string]bool), false}
if err := meta.load(); err != nil {
return nil, err
}
@ -70,18 +68,12 @@ func (m *verMeta) filter(nodes verNodeMap) {
}
func (m *verMeta) removeNode(path string) {
m.mutex.Lock()
m.deleted[path] = true
m.mutex.Unlock()
m.modified = true
}
func (m *verMeta) createNode(path string) {
m.mutex.Lock()
m.deleted[path] = false
m.mutex.Unlock()
m.modified = true
}