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