github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/debug/vlock.go (about) 1 package debug 2 3 import ( 4 "fmt" 5 "runtime" 6 "sync" 7 ) 8 9 // BadMutex is only used to test deadlocks and shouldn't be used in release code. 10 type VLock struct { 11 m sync.Mutex 12 } 13 14 // Lock is a wrapper around a mutex Lock() to help locate deadlocks 15 func (v *VLock) Lock() { 16 _, file1, line1, _ := runtime.Caller(1) 17 _, file2, line2, _ := runtime.Caller(2) 18 Log(fmt.Sprintf("( LOCK ) %s:%d, %s:%d, ", file1, line1, file2, line2)) 19 v.m.Lock() 20 } 21 22 // Lock is a wrapper around a mutex Unlock() to help locate deadlocks 23 func (v *VLock) Unlock() { 24 _, file1, line1, _ := runtime.Caller(1) 25 _, file2, line2, _ := runtime.Caller(2) 26 Log(fmt.Sprintf("(UNLOCK) %s:%d, %s:%d, ", file1, line1, file2, line2)) 27 v.m.Unlock() 28 }