Commit 263918b3 authored by Juan Benet's avatar Juan Benet

Merge pull request #35 from whyrusleeping/fix/sync-batch

fix locking in syncbatch
parents 19e39c85 0f07328c
...@@ -92,24 +92,24 @@ func (d *MutexDatastore) Close() error { ...@@ -92,24 +92,24 @@ func (d *MutexDatastore) Close() error {
} }
type syncBatch struct { type syncBatch struct {
lk sync.Mutex
batch ds.Batch batch ds.Batch
mds *MutexDatastore
} }
func (b *syncBatch) Put(key ds.Key, val interface{}) error { func (b *syncBatch) Put(key ds.Key, val interface{}) error {
b.lk.Lock() b.mds.Lock()
defer b.lk.Unlock() defer b.mds.Unlock()
return b.batch.Put(key, val) return b.batch.Put(key, val)
} }
func (b *syncBatch) Delete(key ds.Key) error { func (b *syncBatch) Delete(key ds.Key) error {
b.lk.Lock() b.mds.Lock()
defer b.lk.Unlock() defer b.mds.Unlock()
return b.batch.Delete(key) return b.batch.Delete(key)
} }
func (b *syncBatch) Commit() error { func (b *syncBatch) Commit() error {
b.lk.Lock() b.mds.Lock()
defer b.lk.Unlock() defer b.mds.Unlock()
return b.batch.Commit() return b.batch.Commit()
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment