Created
August 21, 2024 18:56
-
-
Save maxsei/cd17f57e953b6ebe8f8577bc33dd50c1 to your computer and use it in GitHub Desktop.
debug mutex lol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
"sync" | |
) | |
func NewDebugMutex() sync.Locker { | |
return &debugMutex{} | |
} | |
type debugMutex struct { | |
sync.Mutex | |
} | |
func (m *debugMutex) Lock() { | |
m.Mutex.Lock() | |
_, file, line, ok := runtime.Caller(1) | |
if !ok { | |
panic("Could not get caller information") | |
} | |
println(fmt.Sprintf("Mutex Lock %p: %s:%d", m, file, line)) | |
} | |
func (m *debugMutex) Unlock() { | |
_, file, line, ok := runtime.Caller(1) | |
if !ok { | |
panic("Could not get caller information") | |
} | |
println(fmt.Sprintf("Mutex Unlock %p: %s:%d", m, file, line)) | |
m.Mutex.Unlock() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment