read/write metadata lock

This commit is contained in:
vyzo 2019-04-27 22:19:49 +03:00
parent 0ddad15bd2
commit 3cd491431b

View File

@ -16,7 +16,7 @@ type memoryPeerMetadata struct {
// store other data, like versions
//ds ds.ThreadSafeDatastore
ds map[metakey]interface{}
dslock sync.Mutex
dslock sync.RWMutex
}
var _ pstore.PeerMetadata = (*memoryPeerMetadata)(nil)
@ -35,8 +35,8 @@ func (ps *memoryPeerMetadata) Put(p peer.ID, key string, val interface{}) error
}
func (ps *memoryPeerMetadata) Get(p peer.ID, key string) (interface{}, error) {
ps.dslock.Lock()
defer ps.dslock.Unlock()
ps.dslock.RLock()
defer ps.dslock.RUnlock()
i, ok := ps.ds[metakey{p, key}]
if !ok {
return nil, pstore.ErrNotFound