github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/util/syncutil/mutex_deadlock.go (about) 1 // Copyright 2016 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 //go:build deadlock 12 // +build deadlock 13 14 package syncutil 15 16 import ( 17 "time" 18 19 deadlock "github.com/sasha-s/go-deadlock" 20 ) 21 22 // DeadlockEnabled is true if the deadlock detector is enabled. 23 const DeadlockEnabled = true 24 25 func init() { 26 deadlock.Opts.DeadlockTimeout = 5 * time.Minute 27 } 28 29 // A Mutex is a mutual exclusion lock. 30 type Mutex struct { 31 deadlock.Mutex 32 } 33 34 // AssertHeld is a no-op for deadlock mutexes. 35 func (m *Mutex) AssertHeld() { 36 } 37 38 // TryLock is a no-op for deadlock mutexes. 39 func (rw *Mutex) TryLock() bool { 40 return false 41 } 42 43 // An RWMutex is a reader/writer mutual exclusion lock. 44 type RWMutex struct { 45 deadlock.RWMutex 46 } 47 48 // AssertHeld is a no-op for deadlock mutexes. 49 func (rw *RWMutex) AssertHeld() { 50 } 51 52 // AssertRHeld is a no-op for deadlock mutexes. 53 func (rw *RWMutex) AssertRHeld() { 54 } 55 56 // TryLock is a no-op for deadlock mutexes. 57 func (rw *RWMutex) TryLock() bool { 58 return false 59 }