Documentation
¶
Overview ¶
Package xsync provides synchronization primitives and helpers.
do.go defines the Doer interface and generic helpers to execute functions of various signatures under a lock.
Index ¶
- Variables
- func DoA1[A0 any](ctx context.Context, m Doer, fn func(A0), a0 A0)
- func DoA1R1[A0, R0 any](ctx context.Context, m Doer, fn func(A0) R0, a0 A0) R0
- func DoA1R2[A0, R0, R1 any](ctx context.Context, m Doer, fn func(A0) (R0, R1), a0 A0) (R0, R1)
- func DoA1R4[A0, R0, R1, R2, R3 any](ctx context.Context, m Doer, fn func(A0) (R0, R1, R2, R3), a0 A0) (R0, R1, R2, R3)
- func DoA2[A0, A1 any](ctx context.Context, m Doer, fn func(A0, A1), a0 A0, a1 A1)
- func DoA2R1[A0, A1, R0 any](ctx context.Context, m Doer, fn func(A0, A1) R0, a0 A0, a1 A1) R0
- func DoA2R2[A0, A1, R0, R1 any](ctx context.Context, m Doer, fn func(A0, A1) (R0, R1), a0 A0, a1 A1) (R0, R1)
- func DoA2R3[A0, A1, R0, R1, R2 any](ctx context.Context, m Doer, fn func(A0, A1) (R0, R1, R2), a0 A0, a1 A1) (R0, R1, R2)
- func DoA3[A0, A1, A2 any](ctx context.Context, m Doer, fn func(A0, A1, A2), a0 A0, a1 A1, a2 A2)
- func DoA3R1[A0, A1, A2, R0 any](ctx context.Context, m Doer, fn func(A0, A1, A2) R0, a0 A0, a1 A1, a2 A2) R0
- func DoA3R2[A0, A1, A2, R0, R1 any](ctx context.Context, m Doer, fn func(A0, A1, A2) (R0, R1), a0 A0, a1 A1, a2 A2) (R0, R1)
- func DoA4R1[A0, A1, A2, A3, R0 any](ctx context.Context, m Doer, fn func(A0, A1, A2, A3) R0, a0 A0, a1 A1, a2 A2, ...) R0
- func DoR1[R0 any](ctx context.Context, m Doer, fn func() R0) R0
- func DoR2[R0, R1 any](ctx context.Context, m Doer, fn func() (R0, R1)) (R0, R1)
- func DoR3[R0, R1, R2 any](ctx context.Context, m Doer, fn func() (R0, R1, R2)) (R0, R1, R2)
- func DoR4[R0, R1, R2, R3 any](ctx context.Context, m Doer, fn func() (R0, R1, R2, R3)) (R0, R1, R2, R3)
- func IsAllowUnlockNotLocked(ctx context.Context) bool
- func IsDeadlockDetectorEnabled(ctx context.Context) bool
- func IsEnableDeadlock(ctx context.Context) bool
- func IsLoggingEnabled(ctx context.Context) bool
- func IsNoLogging(ctx context.Context) bool
- func RDoA1[A0 any](ctx context.Context, m RDoer, fn func(A0), a0 A0)
- func RDoA1R1[A0, R0 any](ctx context.Context, m RDoer, fn func(A0) R0, a0 A0) R0
- func RDoA1R2[A0, R0, R1 any](ctx context.Context, m RDoer, fn func(A0) (R0, R1), a0 A0) (R0, R1)
- func RDoA1R4[A0, R0, R1, R2, R3 any](ctx context.Context, m RDoer, fn func(A0) (R0, R1, R2, R3), a0 A0) (R0, R1, R2, R3)
- func RDoA2[A0, A1 any](ctx context.Context, m RDoer, fn func(A0, A1), a0 A0, a1 A1)
- func RDoA2R1[A0, A1, R0 any](ctx context.Context, m RDoer, fn func(A0, A1) R0, a0 A0, a1 A1) R0
- func RDoA2R2[A0, A1, R0, R1 any](ctx context.Context, m RDoer, fn func(A0, A1) (R0, R1), a0 A0, a1 A1) (R0, R1)
- func RDoA2R3[A0, A1, R0, R1, R2 any](ctx context.Context, m RDoer, fn func(A0, A1) (R0, R1, R2), a0 A0, a1 A1) (R0, R1, R2)
- func RDoA3R1[A0, A1, A2, R0 any](ctx context.Context, m RDoer, fn func(A0, A1, A2) R0, a0 A0, a1 A1, a2 A2) R0
- func RDoA4R1[A0, A1, A2, A3, R0 any](ctx context.Context, m RDoer, fn func(A0, A1, A2, A3) R0, a0 A0, a1 A1, a2 A2, ...) R0
- func RDoR1[R0 any](ctx context.Context, m RDoer, fn func() R0) R0
- func RDoR2[R0, R1 any](ctx context.Context, m RDoer, fn func() (R0, R1)) (R0, R1)
- func RDoR3[R0, R1, R2 any](ctx context.Context, m RDoer, fn func() (R0, R1, R2)) (R0, R1, R2)
- func RDoR4[R0, R1, R2, R3 any](ctx context.Context, m RDoer, fn func() (R0, R1, R2, R3)) (R0, R1, R2, R3)
- func SetDeadlockDetectorPossiblyEnabled(v bool)
- func SetLoggingPossiblyEnabled(v bool)
- func WithAllowUnlockNotLocked(ctx context.Context, allow bool) context.Context
- func WithDeadlockDetectorEnabled(ctx context.Context, enableDeadlock bool) context.Context
- func WithEnableDeadlock(ctx context.Context, enableDeadlock bool) context.Context
- func WithLoggingEnabled(ctx context.Context, logging bool) context.Context
- func WithNoLogging(ctx context.Context, noLogging bool) context.Context
- type CtxKeyAllowUnlockNotLocked
- type CtxKeyEnableDeadlock
- type CtxKeyLogging
- type CtxLocker
- type Doer
- type Gorex
- type Map
- func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (m *Map[K, V]) CompareAndSwap(key K, old, new V) (swapped bool)
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Load(key K) (V, bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (m *Map[K, V]) Range(f func(key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key K, value V) (V, bool)
- type Mutex
- func (m *Mutex) Do(ctx context.Context, fn func())
- func (m *Mutex) ManualLock(ctx context.Context)
- func (m *Mutex) ManualRLock(ctx context.Context)
- func (m *Mutex) ManualRUnlock(ctx context.Context)
- func (m *Mutex) ManualTryLock(ctx context.Context) bool
- func (m *Mutex) ManualTryRLock(ctx context.Context) bool
- func (m *Mutex) ManualUnlock(ctx context.Context)
- func (m *Mutex) RDo(ctx context.Context, fn func())
- func (m *Mutex) UDo(ctx context.Context, fn func())
- func (m *Mutex) URDo(ctx context.Context, fn func())
- type Pool
- type RDoer
- type RWMutex
- type WithMutex
Constants ¶
This section is empty.
Variables ¶
var DefaultDeadlockTimeout = time.Minute
Functions ¶
func IsAllowUnlockNotLocked ¶
func IsEnableDeadlock ¶
IsEnableDeadlock returns whether the deadlock detector is enabled.
DEPRECATED: use IsDeadlockDetectorEnabled
func IsLoggingEnabled ¶
func IsNoLogging ¶
IsNoLogging returns whether logging is disabled. DEPRECATED: use IsLoggingEnabled
func SetDeadlockDetectorPossiblyEnabled ¶
func SetDeadlockDetectorPossiblyEnabled(v bool)
SetDeadlockDetectorPossiblyEnabled flips the global fast-path gate for IsDeadlockDetectorEnabled. See SetLoggingPossiblyEnabled for rationale; the same auto-flip behaviour applies via WithDeadlockDetectorEnabled.
func SetLoggingPossiblyEnabled ¶
func SetLoggingPossiblyEnabled(v bool)
SetLoggingPossiblyEnabled flips the global fast-path gate for IsLoggingEnabled. The gate auto-flips to true on the first WithLoggingEnabled(ctx, true) / WithNoLogging(ctx, false) call, so this setter is only needed for callers that want to enable logging without constructing a context, or to forcibly reset the gate (e.g. in tests). While the gate is false, per-context overrides via WithLoggingEnabled are ignored and IsLoggingEnabled always returns false without a context.Value chain walk.
func WithDeadlockDetectorEnabled ¶
WithDeadlockDetectorEnabled returns a context whose IsDeadlockDetectorEnabled answer reflects the given enableDeadlock value. As a side effect, calling it with enableDeadlock == true flips the global deadlockDetectorPossiblyEnabled gate on so the per-context override actually takes effect on the hot RWMutex path. The flip is monotonic-on; passing enableDeadlock == false never flips the gate down because other live contexts may still want the detector enabled.
func WithEnableDeadlock ¶
WithEnableDeadlock sets whether the deadlock detector is enabled. Like WithDeadlockDetectorEnabled, calling it with enableDeadlock == true flips the global deadlockDetectorPossiblyEnabled gate on (monotonic-on).
DEPRECATED: use WithDeadlockDetectorEnabled
func WithLoggingEnabled ¶
WithLoggingEnabled returns a context whose IsLoggingEnabled / IsNoLogging answer reflects the given logging value. As a side effect, calling it with logging == true flips the global loggingPossiblyEnabled gate on so the per-context override actually takes effect on the hot RWMutex path. The flip is monotonic-on; passing logging == false never flips the gate down because other live contexts may still want logging enabled.
func WithNoLogging ¶
WithNoLogging sets whether logging is disabled. As a side effect, calling it with noLogging == false flips the global loggingPossiblyEnabled gate on so the per-context override actually takes effect. The flip is monotonic-on; passing noLogging == true never flips the gate down.
DEPRECATED: use WithLoggingEnabled
Types ¶
type CtxKeyAllowUnlockNotLocked ¶
type CtxKeyAllowUnlockNotLocked struct{}
type CtxKeyEnableDeadlock ¶
type CtxKeyEnableDeadlock struct{}
type CtxKeyLogging ¶
type CtxKeyLogging struct{}
type CtxLocker ¶
type CtxLocker chan struct{}
CtxLocker is a channel-based synchronization primitive that supports context-aware locking. TODO: move to a separate package
func (CtxLocker) ManualUnlock ¶
type Map ¶
type Map[K comparable, V any] struct { sync.Map }
func (*Map[K, V]) CompareAndDelete ¶
func (*Map[K, V]) CompareAndSwap ¶
func (*Map[K, V]) LoadAndDelete ¶
func (*Map[K, V]) LoadOrStore ¶
type Mutex ¶
type Mutex = RWMutex