syncs: add Mutex/RWMutex alias/wrappers for future mutex debugging

Updates #17852

Change-Id: I477340fb8e40686870e981ade11cd61597c34a20
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2025-11-15 09:40:57 -08:00
committed by Brad Fitzpatrick
parent 3a41c0c585
commit 99b06eac49
55 changed files with 145 additions and 94 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ import (
)
// AssertLocked panics if m is not locked.
func AssertLocked(m *sync.Mutex) {
func AssertLocked(m *Mutex) {
if m.TryLock() {
m.Unlock()
panic("mutex is not locked")
@@ -16,7 +16,7 @@ func AssertLocked(m *sync.Mutex) {
}
// AssertRLocked panics if rw is not locked for reading or writing.
func AssertRLocked(rw *sync.RWMutex) {
func AssertRLocked(rw *RWMutex) {
if rw.TryLock() {
rw.Unlock()
panic("mutex is not locked")
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_mutex_debug
package syncs
import "sync"
// Mutex is an alias for sync.Mutex.
//
// It's only not a sync.Mutex when built with the ts_mutex_debug build tag.
type Mutex = sync.Mutex
// RWMutex is an alias for sync.RWMutex.
//
// It's only not a sync.RWMutex when built with the ts_mutex_debug build tag.
type RWMutex = sync.RWMutex
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build ts_mutex_debug
package syncs
import "sync"
type Mutex struct {
sync.Mutex
}
type RWMutex struct {
sync.RWMutex
}
// TODO(bradfitz): actually track stuff when in debug mode.
+2 -1
View File
@@ -1,13 +1,14 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package syncs
package syncs_test
import (
"expvar"
"sync"
"testing"
. "tailscale.com/syncs"
"tailscale.com/tstest"
)