提交 b0364396 作者: Juan Batiz-Benet

Merge pull request #937 from jbenet/fix/pinning-locks

fix locking in the pinner
...@@ -200,6 +200,8 @@ func (p *pinner) IsPinned(key util.Key) bool { ...@@ -200,6 +200,8 @@ func (p *pinner) IsPinned(key util.Key) bool {
} }
func (p *pinner) RemovePinWithMode(key util.Key, mode PinMode) { func (p *pinner) RemovePinWithMode(key util.Key, mode PinMode) {
p.lock.Lock()
defer p.lock.Unlock()
switch mode { switch mode {
case Direct: case Direct:
p.directPin.RemoveBlock(key) p.directPin.RemoveBlock(key)
...@@ -265,8 +267,8 @@ func (p *pinner) RecursiveKeys() []util.Key { ...@@ -265,8 +267,8 @@ func (p *pinner) RecursiveKeys() []util.Key {
// Flush encodes and writes pinner keysets to the datastore // Flush encodes and writes pinner keysets to the datastore
func (p *pinner) Flush() error { func (p *pinner) Flush() error {
p.lock.RLock() p.lock.Lock()
defer p.lock.RUnlock() defer p.lock.Unlock()
err := storeSet(p.dstore, directPinDatastoreKey, p.directPin.GetKeys()) err := storeSet(p.dstore, directPinDatastoreKey, p.directPin.GetKeys())
if err != nil { if err != nil {
...@@ -311,6 +313,8 @@ func loadSet(d ds.Datastore, k ds.Key, val interface{}) error { ...@@ -311,6 +313,8 @@ func loadSet(d ds.Datastore, k ds.Key, val interface{}) error {
// PinWithMode is a method on ManualPinners, allowing the user to have fine // PinWithMode is a method on ManualPinners, allowing the user to have fine
// grained control over pin counts // grained control over pin counts
func (p *pinner) PinWithMode(k util.Key, mode PinMode) { func (p *pinner) PinWithMode(k util.Key, mode PinMode) {
p.lock.Lock()
defer p.lock.Unlock()
switch mode { switch mode {
case Recursive: case Recursive:
p.recursePin.AddBlock(k) p.recursePin.AddBlock(k)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论