]> Sergey Matveev's repositories - btrtrc.git/blobdiff - deferrwl.go
Make fs a separate module
[btrtrc.git] / deferrwl.go
index 3b2ad7a3a2e7b59162b54426ffb800daec1c88b5..bf95be244f064880a6117a1358304e5db634d1af 100644 (file)
@@ -1,6 +1,6 @@
 package torrent
 
-import "sync"
+import "github.com/anacrolix/sync"
 
 // Runs deferred actions on Unlock. Note that actions are assumed to be the results of changes that
 // would only occur with a write lock at present. The race detector should catch instances of defers
@@ -15,10 +15,11 @@ func (me *lockWithDeferreds) Lock() {
 }
 
 func (me *lockWithDeferreds) Unlock() {
-       for _, a := range me.unlockActions {
-               a()
+       unlockActions := me.unlockActions
+       for i := 0; i < len(unlockActions); i += 1 {
+               unlockActions[i]()
        }
-       me.unlockActions = me.unlockActions[:0]
+       me.unlockActions = unlockActions[:0]
        me.internal.Unlock()
 }