xsync

package module
v0.0.0-...-2560424 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: BSD-3-Clause, MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyMutex

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

KeyMutex is an associative mutual exclusion lock. The zero value for a KeyMutex contains unlocked keys.

func (*KeyMutex) Lock

func (k *KeyMutex) Lock(key string)

Lock locks a mutex associated with a key.

func (*KeyMutex) Unlock

func (k *KeyMutex) Unlock(key string)

Unlock unlocks a mutex associated with key. It is a runtime error if the associated mutex is not locked on entry to Unlock.

type Semaphore

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

Semaphore provides counted mutual exclusion. The zero value for a Semaphore is ready for use. A Semaphore must not be copied after first use.

Unlike x/sync/semaphore, it is valid to release tickets after initialization.

func NewSemaphore

func NewSemaphore(tickets uint32) Semaphore

New creates a new semaphore with the given count of tickets.

func (*Semaphore) Acquire

func (s *Semaphore) Acquire()

Acquire a ticket, blocking until one is available.

func (*Semaphore) Release

func (s *Semaphore) Release()

Release adds a ticket and signals the next waiter. There is a maximum of 1<<32 tickets, at which point Release() will overflow. Callers are responsible for avoiding this overflow.

func (*Semaphore) TryAcquire

func (s *Semaphore) TryAcquire() bool

TryAcquire attempts to acquire a ticket without blocking. On success, returns true. On failure, returns false and leaves the semaphore unchanged.

Jump to

Keyboard shortcuts

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