Skip to content

Commit

Permalink
Use RWMutex instead of Mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
dddddai committed Jul 21, 2020
1 parent c2e6384 commit 196789f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pkg/minikube/registry/registry.go
Expand Up @@ -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 {
Expand All @@ -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))

Expand All @@ -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]
}
12 changes: 6 additions & 6 deletions third_party/go9p/srv_file.go
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 196789f

Please sign in to comment.