safe

package
v3.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lock

func Lock(fn func(), m ...Mutex)

Lock locks one or more mutexes for writing and calls the given function. The mutexes are locked in a deterministic order to avoid deadlocks.

func LockRet

func LockRet[T any](fn func() T, m ...Mutex) T

LockRet locks one or more mutexes for writing and calls the given function, returning a value.

func LockRetErr

func LockRetErr[T any](fn func() (T, error), m ...Mutex) (T, error)

LockRetErr locks one or more mutexes for writing and calls the given function, returning a value and an error.

func RLock

func RLock(fn func(), m ...RWMutex)

RLock locks one or more mutexes for reading and calls the given function. The mutexes are locked in a deterministic order to avoid deadlocks.

func RLockRet

func RLockRet[T any](fn func() T, m ...RWMutex) T

RLockRet locks one or more mutexes for reading and calls the given function, returning a value.

func RLockRetErr

func RLockRetErr[T any](fn func() (T, error), m ...RWMutex) (T, error)

RLockRetErr locks one or more mutexes for reading and calls the given function, returning a value and an error.

Types

type Mutex

type Mutex interface {
	Lock()
	Unlock()
	// contains filtered or unexported methods
}

Mutex is a mutex that can be locked and unlocked.

func NewMutex

func NewMutex() Mutex

NewMutex returns a new mutex.

type RWMutex

type RWMutex interface {
	Mutex

	RLock()
	RUnlock()
}

RWMutex is a mutex that can be locked and unlocked for reading and writing.

func NewRWMutex

func NewRWMutex() RWMutex

NewRWMutex returns a new read-write mutex.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL