3 import "github.com/anacrolix/sync"
5 // Runs deferred actions on Unlock. Note that actions are assumed to be the results of changes that
6 // would only occur with a write lock at present. The race detector should catch instances of defers
7 // without the write lock being held.
8 type lockWithDeferreds struct {
10 unlockActions []func()
13 func (me *lockWithDeferreds) Lock() {
17 func (me *lockWithDeferreds) Unlock() {
18 unlockActions := me.unlockActions
19 for i := 0; i < len(unlockActions); i += 1 {
22 me.unlockActions = unlockActions[:0]
26 func (me *lockWithDeferreds) RLock() {
30 func (me *lockWithDeferreds) RUnlock() {
34 func (me *lockWithDeferreds) Defer(action func()) {
35 me.unlockActions = append(me.unlockActions, action)