Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DisableLogging = false // global flag to disable logging and bypass directly to original mutexes without counting
View Source
var GlobalDebug = false // global debug flag for all mutexes
Any Debug flags can only be set on boot time / before initializing any mutexes or you may get data race errors. this is a non fix as this package is only for debugging purposes.
Functions ¶
This section is empty.
Types ¶
type LoggedSyncRWMutex ¶
type LoggedSyncRWMutex struct {
Name string
DebugAll bool // if true, will print debug messages
DebugLock bool // if true, will print debug messages
DebugUnlock bool // if true, will print debug messages
DebugRLock bool // if true, will print debug messages
DebugRUnlock bool // if true, will print debug messages
sync.RWMutex // the actual mutex that will be used for locking
// contains filtered or unexported fields
}
LoggedSyncRWMutex is a mutex that logs its actions. It wraps sync.Mutex and sync.RWMutex to provide logging for lock and unlock actions. This is useful for debugging and tracking mutex usage in concurrent applications. It can be used in place of sync.RWMutex. Usage: import : "github.com/go-while/go-loggedrwmutex"
func init() {
loggedrwmutex.GlobalDebug = true // enables global debug messages for all mutexes}
}
var mux *loggedrwmutex.LoggedSyncRWMutex
mux := &loggedrwmutexLoggedSyncRWMutex{Name: "XXYYZZ" }'
item.mux = mux
item.mux.DebugAll = true // enables all debug messages
item.mux.DebugLock = true // enables debug messages for Lock
item.mux.DebugUnlock = true // enables debug messages for Unlock
item.mux.DebugRLock = true // enables debug messages for RLock
item.mux.DebugRUnlock = true // enables debug messages for RUnlock
item.mux.Lock() // locks the mutex
item.mux.Unlock() // unlocks the mutex
item.mux.RLock() // acquires a read lock
item.mux.RUnlock() // releases a read lock
locked, rlocked := item.mux.Status(true) // checks the status of the mutex
func (*LoggedSyncRWMutex) Lock ¶
func (m *LoggedSyncRWMutex) Lock()
func (*LoggedSyncRWMutex) PrintStatus ¶
func (m *LoggedSyncRWMutex) PrintStatus(forceprint bool) (locked bool, rlocked bool)
Status prints the current status of the mutex, including whether it is locked or read-locked.
func (*LoggedSyncRWMutex) RLock ¶
func (m *LoggedSyncRWMutex) RLock()
func (*LoggedSyncRWMutex) RUnlock ¶
func (m *LoggedSyncRWMutex) RUnlock()
func (*LoggedSyncRWMutex) Unlock ¶
func (m *LoggedSyncRWMutex) Unlock()
Click to show internal directories.
Click to hide internal directories.