1package libkb 2 3import ( 4 "fmt" 5 "sync" 6) 7 8type VerboseLockRelease = func() 9 10type VerboseLock struct { 11 mu sync.Mutex 12 level VDebugLevel 13 name string 14} 15 16func NewVerboseLock(level VDebugLevel, name string) *VerboseLock { 17 return &VerboseLock{ 18 level: level, 19 name: name, 20 } 21} 22 23func (l *VerboseLock) Acquire(mctx MetaContext, reasonFormat string, args ...interface{}) (release VerboseLockRelease) { 24 reason := fmt.Sprintf(reasonFormat, args...) 25 log := func(symbol string, word string) { 26 mctx.VLogf(l.level, "%v VerboseLock [%v] %v: %v", symbol, l.name, word, reason) 27 } 28 log("+", "acquiring") 29 l.mu.Lock() 30 log("|", "acquired") 31 return func() { 32 l.mu.Unlock() 33 log("-", "released") 34 } 35} 36