Files
tailscale/syncs/locked.go
Brad Fitzpatrick 99b06eac49 syncs: add Mutex/RWMutex alias/wrappers for future mutex debugging
Updates #17852

Change-Id: I477340fb8e40686870e981ade11cd61597c34a20
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-11-16 19:13:59 -08:00

33 lines
599 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package syncs
import (
"sync"
)
// AssertLocked panics if m is not locked.
func AssertLocked(m *Mutex) {
if m.TryLock() {
m.Unlock()
panic("mutex is not locked")
}
}
// AssertRLocked panics if rw is not locked for reading or writing.
func AssertRLocked(rw *RWMutex) {
if rw.TryLock() {
rw.Unlock()
panic("mutex is not locked")
}
}
// AssertWLocked panics if rw is not locked for writing.
func AssertWLocked(rw *sync.RWMutex) {
if rw.TryRLock() {
rw.RUnlock()
panic("mutex is not rlocked")
}
}