Use RWMutex instead of Mutex

pull/8737/head
dddddai 2020-07-17 08:11:00 +08:00
parent c2e63844db
commit 196789f965
2 changed files with 11 additions and 11 deletions

View File

@ -109,7 +109,7 @@ func (d DriverDef) String() string {
type driverRegistry struct {
drivers map[string]DriverDef
lock sync.Mutex
lock sync.RWMutex
}
func newRegistry() *driverRegistry {
@ -133,8 +133,8 @@ func (r *driverRegistry) Register(def DriverDef) error {
// List returns a list of registered drivers
func (r *driverRegistry) List() []DriverDef {
r.lock.Lock()
defer r.lock.Unlock()
r.lock.RLock()
defer r.lock.RUnlock()
result := make([]DriverDef, 0, len(r.drivers))
@ -147,7 +147,7 @@ func (r *driverRegistry) List() []DriverDef {
// Driver returns a driver given a name
func (r *driverRegistry) Driver(name string) DriverDef {
r.lock.Lock()
defer r.lock.Unlock()
r.lock.RLock()
defer r.lock.RUnlock()
return r.drivers[name]
}

View File

@ -81,7 +81,7 @@ const (
// The srvFile type represents a file (or directory) served by the file server.
type srvFile struct {
sync.Mutex
sync.RWMutex
Dir
flags FFlags
@ -239,13 +239,13 @@ func (f *srvFile) Rename(name string) error {
func (p *srvFile) Find(name string) *srvFile {
var f *srvFile
p.Lock()
p.RLock()
for f = p.cfirst; f != nil; f = f.next {
if name == f.Name {
break
}
}
p.Unlock()
p.RUnlock()
return f
}
@ -496,13 +496,13 @@ func (*Fsrv) Clunk(req *SrvReq) {
func (*Fsrv) Remove(req *SrvReq) {
fid := req.Fid.Aux.(*FFid)
f := fid.F
f.Lock()
f.RLock()
if f.cfirst != nil {
f.Unlock()
f.RUnlock()
req.RespondError(Enotempty)
return
}
f.Unlock()
f.RUnlock()
if rop, ok := (f.ops).(FRemoveOp); ok {
err := rop.Remove(fid)