github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/util/syncutil/mutex_sync.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 && !race 12 // +build !deadlock,!race 13 14 package syncutil 15 16 import "sync" 17 18 // DeadlockEnabled is true if the deadlock detector is enabled. 19 const DeadlockEnabled = false 20 21 // A Mutex is a mutual exclusion lock. 22 type Mutex struct { 23 sync.Mutex 24 } 25 26 // AssertHeld may panic if the mutex is not locked (but it is not required to 27 // do so). Functions which require that their callers hold a particular lock 28 // may use this to enforce this requirement more directly than relying on the 29 // race detector. 30 // 31 // Note that we do not require the lock to be held by any particular thread, 32 // just that some thread holds the lock. This is both more efficient and allows 33 // for rare cases where a mutex is locked in one thread and used in another. 34 func (m *Mutex) AssertHeld() { 35 } 36 37 // An RWMutex is a reader/writer mutual exclusion lock. 38 type RWMutex struct { 39 sync.RWMutex 40 } 41 42 // AssertHeld may panic if the mutex is not locked for writing (but it is not 43 // required to do so). Functions which require that their callers hold a 44 // particular lock may use this to enforce this requirement more directly than 45 // relying on the race detector. 46 // 47 // Note that we do not require the exclusive lock to be held by any particular 48 // thread, just that some thread holds the lock. This is both more efficient 49 // and allows for rare cases where a mutex is locked in one thread and used in 50 // another. 51 func (rw *RWMutex) AssertHeld() { 52 } 53 54 // AssertRHeld may panic if the mutex is not locked for reading (but it is not 55 // required to do so). If the mutex is locked for writing, it is also considered 56 // to be locked for reading. Functions which require that their callers hold a 57 // particular lock may use this to enforce this requirement more directly than 58 // relying on the race detector. 59 // 60 // Note that we do not require the shared lock to be held by any particular 61 // thread, just that some thread holds the lock. This is both more efficient 62 // and allows for rare cases where a mutex is locked in one thread and used in 63 // another. 64 func (rw *RWMutex) AssertRHeld() { 65 }