pkg/wait: change list's lock to RWMutex

Change list's lock from Mutex to RWMutex, which allows concurrent
access for list.IsRegistered function.
This commit is contained in:
lorneli 2017-08-27 18:03:31 +08:00
parent c9f677c0ea
commit 54fcdb4b5c

View File

@ -34,7 +34,7 @@ type Wait interface {
} }
type list struct { type list struct {
l sync.Mutex l sync.RWMutex
m map[uint64]chan interface{} m map[uint64]chan interface{}
} }
@ -68,8 +68,8 @@ func (w *list) Trigger(id uint64, x interface{}) {
} }
func (w *list) IsRegistered(id uint64) bool { func (w *list) IsRegistered(id uint64) bool {
w.l.Lock() w.l.RLock()
defer w.l.Unlock() defer w.l.RUnlock()
_, ok := w.m[id] _, ok := w.m[id]
return ok return ok
} }