syncs

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: BSD-3-Clause Imports: 5 Imported by: 60

Documentation

Overview

Package syncs contains additional sync types and functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertLocked added in v1.14.0

func AssertLocked(m *sync.Mutex)

AssertLocked panics if m is not locked.

func AssertRLocked added in v1.14.0

func AssertRLocked(rw *sync.RWMutex)

AssertRLocked panics if rw is not locked for reading or writing.

func AssertWLocked added in v1.14.0

func AssertWLocked(rw *sync.RWMutex)

AssertWLocked panics if rw is not locked for writing.

func ClosedChan

func ClosedChan() <-chan struct{}

ClosedChan returns a channel that's already closed.

func Watch added in v1.2.0

func Watch(ctx context.Context, mu sync.Locker, tick, max time.Duration) chan time.Duration

Watch monitors mu for contention. On first call, and at every tick, Watch locks and unlocks mu. (Tick should be large to avoid adding contention to mu.) Max is the maximum length of time Watch will wait to acquire the lock. The time required to lock mu is sent on the returned channel. Watch exits when ctx is done, and closes the returned channel.

Types

type AtomicBool added in v0.98.1

type AtomicBool int32

AtomicBool is an atomic boolean.

func (*AtomicBool) Get added in v0.98.1

func (b *AtomicBool) Get() bool

func (*AtomicBool) Set added in v0.98.1

func (b *AtomicBool) Set(v bool)

func (*AtomicBool) Swap added in v1.12.0

func (b *AtomicBool) Swap(v bool) (changed bool)

Swap sets b to v and reports whether it changed.

type AtomicUint32 added in v1.10.0

type AtomicUint32 uint32

AtomicUint32 is an atomic uint32.

func (*AtomicUint32) Get added in v1.10.0

func (b *AtomicUint32) Get() uint32

func (*AtomicUint32) Set added in v1.10.0

func (b *AtomicUint32) Set(v uint32)

type Semaphore added in v1.8.0

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

Semaphore is a counting semaphore.

Use NewSemaphore to create one.

func NewSemaphore added in v1.8.0

func NewSemaphore(n int) Semaphore

NewSemaphore returns a semaphore with resource count n.

func (Semaphore) Acquire added in v1.8.0

func (s Semaphore) Acquire()

Acquire blocks until a resource is acquired.

func (Semaphore) AcquireContext added in v1.8.0

func (s Semaphore) AcquireContext(ctx context.Context) bool

AcquireContext reports whether the resource was acquired before the ctx was done.

func (Semaphore) Release added in v1.8.0

func (s Semaphore) Release()

Release releases a resource.

func (Semaphore) TryAcquire added in v1.8.0

func (s Semaphore) TryAcquire() bool

TryAcquire reports, without blocking, whether the resource was acquired.

type WaitGroupChan

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

WaitGroupChan is like a sync.WaitGroup, but has a chan that closes on completion that you can wait on. (This, you can only use the value once) Also, its zero value is not usable. Use the constructor.

func NewWaitGroupChan

func NewWaitGroupChan() *WaitGroupChan

NewWaitGroupChan returns a new single-use WaitGroupChan.

func (*WaitGroupChan) Add

func (wg *WaitGroupChan) Add(delta int)

Add adds delta, which may be negative, to the WaitGroupChan counter. If the counter becomes zero, all goroutines blocked on Wait or the Done chan are released. If the counter goes negative, Add panics.

Note that calls with a positive delta that occur when the counter is zero must happen before a Wait. Calls with a negative delta, or calls with a positive delta that start when the counter is greater than zero, may happen at any time. Typically this means the calls to Add should execute before the statement creating the goroutine or other event to be waited for.

func (*WaitGroupChan) Decr

func (wg *WaitGroupChan) Decr()

Decr decrements the WaitGroup counter by one.

(It is like sync.WaitGroup's Done method, but we don't use Done in this type, because it's ambiguous between Context.Done and WaitGroup.Done. So we use DoneChan and Decr instead.)

func (*WaitGroupChan) DoneChan

func (wg *WaitGroupChan) DoneChan() <-chan struct{}

DoneChan returns a channel that's closed on completion.

func (*WaitGroupChan) Wait

func (wg *WaitGroupChan) Wait()

Wait blocks until the WaitGroupChan counter is zero.

Jump to

Keyboard shortcuts

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