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.
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 ¶
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 ¶
TryAcquire attempts to acquire a ticket without blocking. On success, returns true. On failure, returns false and leaves the semaphore unchanged.