Use RWMutex instead of Mutex
parent
c2e63844db
commit
196789f965
|
@ -109,7 +109,7 @@ func (d DriverDef) String() string {
|
||||||
|
|
||||||
type driverRegistry struct {
|
type driverRegistry struct {
|
||||||
drivers map[string]DriverDef
|
drivers map[string]DriverDef
|
||||||
lock sync.Mutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRegistry() *driverRegistry {
|
func newRegistry() *driverRegistry {
|
||||||
|
@ -133,8 +133,8 @@ func (r *driverRegistry) Register(def DriverDef) error {
|
||||||
|
|
||||||
// List returns a list of registered drivers
|
// List returns a list of registered drivers
|
||||||
func (r *driverRegistry) List() []DriverDef {
|
func (r *driverRegistry) List() []DriverDef {
|
||||||
r.lock.Lock()
|
r.lock.RLock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.RUnlock()
|
||||||
|
|
||||||
result := make([]DriverDef, 0, len(r.drivers))
|
result := make([]DriverDef, 0, len(r.drivers))
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ func (r *driverRegistry) List() []DriverDef {
|
||||||
|
|
||||||
// Driver returns a driver given a name
|
// Driver returns a driver given a name
|
||||||
func (r *driverRegistry) Driver(name string) DriverDef {
|
func (r *driverRegistry) Driver(name string) DriverDef {
|
||||||
r.lock.Lock()
|
r.lock.RLock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.RUnlock()
|
||||||
return r.drivers[name]
|
return r.drivers[name]
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ const (
|
||||||
|
|
||||||
// The srvFile type represents a file (or directory) served by the file server.
|
// The srvFile type represents a file (or directory) served by the file server.
|
||||||
type srvFile struct {
|
type srvFile struct {
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
Dir
|
Dir
|
||||||
flags FFlags
|
flags FFlags
|
||||||
|
|
||||||
|
@ -239,13 +239,13 @@ func (f *srvFile) Rename(name string) error {
|
||||||
func (p *srvFile) Find(name string) *srvFile {
|
func (p *srvFile) Find(name string) *srvFile {
|
||||||
var f *srvFile
|
var f *srvFile
|
||||||
|
|
||||||
p.Lock()
|
p.RLock()
|
||||||
for f = p.cfirst; f != nil; f = f.next {
|
for f = p.cfirst; f != nil; f = f.next {
|
||||||
if name == f.Name {
|
if name == f.Name {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.Unlock()
|
p.RUnlock()
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,13 +496,13 @@ func (*Fsrv) Clunk(req *SrvReq) {
|
||||||
func (*Fsrv) Remove(req *SrvReq) {
|
func (*Fsrv) Remove(req *SrvReq) {
|
||||||
fid := req.Fid.Aux.(*FFid)
|
fid := req.Fid.Aux.(*FFid)
|
||||||
f := fid.F
|
f := fid.F
|
||||||
f.Lock()
|
f.RLock()
|
||||||
if f.cfirst != nil {
|
if f.cfirst != nil {
|
||||||
f.Unlock()
|
f.RUnlock()
|
||||||
req.RespondError(Enotempty)
|
req.RespondError(Enotempty)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f.Unlock()
|
f.RUnlock()
|
||||||
|
|
||||||
if rop, ok := (f.ops).(FRemoveOp); ok {
|
if rop, ok := (f.ops).(FRemoveOp); ok {
|
||||||
err := rop.Remove(fid)
|
err := rop.Remove(fid)
|
||||||
|
|
Loading…
Reference in New Issue