Merge pull request #287 from bluefoxah/master

modify the lock
This commit is contained in:
Chris Lu 2016-04-11 01:11:49 -07:00
commit b873b856f2

View file

@ -8,7 +8,6 @@ import (
// initialize the map entries. // initialize the map entries.
type ConcurrentReadMap struct { type ConcurrentReadMap struct {
rmutex sync.RWMutex rmutex sync.RWMutex
mutex sync.Mutex
Items map[string]interface{} Items map[string]interface{}
} }
@ -17,8 +16,8 @@ func NewConcurrentReadMap() *ConcurrentReadMap {
} }
func (m *ConcurrentReadMap) initMapEntry(key string, newEntry func() interface{}) (value interface{}) { func (m *ConcurrentReadMap) initMapEntry(key string, newEntry func() interface{}) (value interface{}) {
m.mutex.Lock() m.rmutex.Lock()
defer m.mutex.Unlock() defer m.rmutex.Unlock()
if value, ok := m.Items[key]; ok { if value, ok := m.Items[key]; ok {
return value return value
} }