syncutil

package
v0.0.0-...-2ee2aa9 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package syncutil contains structs and helpers to simplify concurrency

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NamedMutex

type NamedMutex struct {
	// contains filtered or unexported fields
}

NamedMutex is a struct allowing to lock/unlock using a key It is expected that 2 keys may collide

func NewNamedMutex

func NewNamedMutex(maxMutexes uint32) *NamedMutex

NewNamedMutex creates a new NamedMutex with the given capacity. If the max number is below 2, 2 will be used. using a prime number as max offers better performance

func (*NamedMutex) Lock

func (mu *NamedMutex) Lock(key []byte)

Lock locks the provided key. If the lock is already in use, the calling goroutine blocks until the mutex is available.

func (*NamedMutex) RLock

func (mu *NamedMutex) RLock(key []byte)

RLock locks rw for reading. It should not be used for recursive read locking; a blocked Lock call excludes new readers from acquiring the lock. See the documentation on the RWMutex type.

func (*NamedMutex) RUnlock

func (mu *NamedMutex) RUnlock(key []byte)

RUnlock undoes a single RLock call; it does not affect other simultaneous readers. It is a run-time error if rw is not locked for reading on entry to RUnlock.

func (*NamedMutex) Unlock

func (mu *NamedMutex) Unlock(key []byte)

Unlock unlocks the provided key. It is a run-time error if the key is not locked on entry to Unlock.

Jump to

Keyboard shortcuts

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