Documentation
¶
Index ¶
- Constants
- Variables
- type G
- type Mutex
- type RWMutex
- func (m *RWMutex) Lock()
- func (m *RWMutex) LockCtx(ctx context.Context) bool
- func (m *RWMutex) LockCtxDo(ctx context.Context, fn func()) (success bool)
- func (m *RWMutex) LockDo(fn func())
- func (m *RWMutex) LockTry() bool
- func (m *RWMutex) LockTryDo(fn func()) (success bool)
- func (m *RWMutex) RLock()
- func (m *RWMutex) RLockCtx(ctx context.Context) bool
- func (m *RWMutex) RLockCtxDo(ctx context.Context, fn func()) (success bool)
- func (m *RWMutex) RLockDo(fn func())
- func (m *RWMutex) RLockTry() bool
- func (m *RWMutex) RLockTryDo(fn func()) (success bool)
- func (m *RWMutex) RUnlock()
- func (m *RWMutex) Unlock()
Constants ¶
const GO_VERSION = ">=go1.23"
Variables ¶
var DefaultInfiniteContext = context.Background()
DefaultInfiniteContext is used as the default context used on any try to lock if a custom context is not set (see LockCtx/RLockCtx), but with the difference if this context will be done, then it will panic with debugging information.
To specify a context with deadline may be useful for unit tests.
Functions ¶
This section is empty.
Types ¶
type Mutex ¶
type Mutex struct {
// InfiniteContext is used as the default context used on any try to lock if
// a custom context is not set (see LockCtx), but with the difference
// if this context will be done, then it will panic with debugging information.
//
// To specify a context with deadline may be useful for unit tests.
//
// The zero-value means to use DefaultInfiniteContext.
InfiniteContext context.Context
// contains filtered or unexported fields
}
Mutex is a goroutine-aware analog of sync.Mutex, so it works the same way as sync.Mutex, but tracks which goroutine locked it. So it could be locked multiple times with the same routine.
func (*Mutex) Lock ¶
func (m *Mutex) Lock()
Lock is analog of `(*sync.Mutex)`.Lock, but it allows one goroutine to call it multiple times without calling Unlock.
func (*Mutex) LockCtx ¶
LockCtx is analog of Lock(), but allows to continue the try to lock only until context is done..
Returns `false` if was unable to lock (context finished before it was possible to lock).
func (*Mutex) LockCtxDo ¶
LockCtxDo is a wrapper around LockCtx and Unlock.
See also LockDo and LockCtx.
func (*Mutex) LockDo ¶
func (m *Mutex) LockDo(fn func())
LockDo is a wrapper around Lock and Unlock. It's a handy function to see in the call stack trace which locker where was locked. Also it's handy not to forget to unlock the locker.
func (*Mutex) LockTry ¶
LockTry is analog of Lock(), but it does not block if it cannot lock right away.
Returns `false` if was unable to lock.
type RWMutex ¶
type RWMutex struct {
// InfiniteContext is used as the default context used on any try to lock if
// a custom context is not set (see LockCtx/RLockCtx), but with the difference
// if this context will be done, then it will panic with debugging information.
//
// To specify a context with deadline may be useful for unit tests.
//
// The zero-value means to use DefaultInfiniteContext.
InfiniteContext context.Context
// contains filtered or unexported fields
}
RWMutex is a goroutine-aware analog of sync.RWMutex, so it works the same way as sync.RWMutex, but tracks which goroutine locked it. So it could be locked multiple times with the same routine.
func (*RWMutex) Lock ¶
func (m *RWMutex) Lock()
Lock is analog of `(*sync.RWMutex)`.Lock, but it allows one goroutine to call it and RLock multiple times without calling Unlock/RUnlock.
func (*RWMutex) LockCtx ¶
LockCtx is analog of Lock(), but allows to continue the try to lock only until context is done.
Returns `false` if was unable to lock (context finished before it was possible to lock).
func (*RWMutex) LockCtxDo ¶
LockCtxDo is a wrapper around LockCtx and Unlock.
See also LockDo and LockCtx.
func (*RWMutex) LockDo ¶
func (m *RWMutex) LockDo(fn func())
LockDo is a wrapper around Lock and Unlock. It's a handy function to see in the call stack trace which locker where was locked. Also it's handy not to forget to unlock the locker.
func (*RWMutex) LockTry ¶
LockTry is analog of Lock(), but it does not block if it cannot lock right away.
Returns `false` if was unable to lock.
func (*RWMutex) LockTryDo ¶
LockTryDo is a wrapper around LockTry and Unlock.
See also LockDo and LockTry.
func (*RWMutex) RLock ¶
func (m *RWMutex) RLock()
RLock is analog of `(*sync.RWMutex)`.RLock, but it allows one goroutine to call Lock and RLock multiple times without calling Unlock/RUnlock.
func (*RWMutex) RLockCtx ¶
RLockCtx is analog of RLock(), but allows to continue the try to lock only until context is done.
Returns `false` if was unable to lock.
func (*RWMutex) RLockCtxDo ¶
RLockCtxDo is a wrapper around RLockTry and RUnlock.
See also RLockDo and RLockCtx.
func (*RWMutex) RLockDo ¶
func (m *RWMutex) RLockDo(fn func())
RLockDo is a wrapper around RLock and RUnlock. It's a handy function to see in the call stack trace which locker where was locked. Also it's handy not to forget to unlock the locker.
func (*RWMutex) RLockTry ¶
RLockTry is analog of RLock(), but it does not block if it cannot lock right away.
Returns `false` if was unable to lock.
func (*RWMutex) RLockTryDo ¶
RLockTryDo is a wrapper around RLockTry and RUnlock.
See also RLockDo and RLockTry.