fix locking in the pinner
Jeromy committed
Mar 17, 2015 at 14:51 UTC
8d81a8b8d9c74efd1d5498a764c9173366da7da4
1 file changed
+6
-2
pin/pin.go
+6
-2
@@ -200,6 +200,8 @@ func (p *pinner) IsPinned(key util.Key) bool {
200
}
201
202
func (p *pinner) RemovePinWithMode(key util.Key, mode PinMode) {
203
+ p.lock.Lock()
204
+ defer p.lock.Unlock()
205
switch mode {
206
case Direct:
207
p.directPin.RemoveBlock(key)
@@ -265,8 +267,8 @@ func (p *pinner) RecursiveKeys() []util.Key {
267
268
// Flush encodes and writes pinner keysets to the datastore
269
func (p *pinner) Flush() error {
268
- p.lock.RLock()
269
- defer p.lock.RUnlock()
270
+ p.lock.Lock()
271
+ defer p.lock.Unlock()
272
273
err := storeSet(p.dstore, directPinDatastoreKey, p.directPin.GetKeys())
274
if err != nil {
@@ -311,6 +313,8 @@ func loadSet(d ds.Datastore, k ds.Key, val interface{}) error {
313
// PinWithMode is a method on ManualPinners, allowing the user to have fine
314
// grained control over pin counts
315
func (p *pinner) PinWithMode(k util.Key, mode PinMode) {
316
+ p.lock.Lock()
317
+ defer p.lock.Unlock()
318
switch mode {
319
case Recursive:
320
p.recursePin.AddBlock(k)