syncutil

package
v2.1.7+incompatible Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

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

Lock is a channel based lock with TryLock() supported, it is designed for very low contention scenario

func NewLock

func NewLock() *Lock

NewLock creates a new Lock instance.

func (*Lock) Lock

func (l *Lock) Lock()

Lock blocks the calling thread until the lock is acquired.

func (*Lock) TryLock

func (l *Lock) TryLock() bool

TryLock tries to acquire the lock and returns a boolean value to indicate whether the lock is successfully acquired.

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock unlocks the lock.

type Stopper

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

Stopper is a manager struct for managing worker goroutines. It is modified from an early version of the stopper struct found in CockroachDB's codebase.

func NewStopper

func NewStopper() *Stopper

NewStopper return a new Stopper instance.

func (*Stopper) Close

func (s *Stopper) Close()

Close closes the internal shouldStopc chan struct{} to signal all worker goroutines that they should stop.

func (*Stopper) RunNamedWorker

func (s *Stopper) RunNamedWorker(f func(), name string)

RunNamedWorker creates a new gorotuine and invoke the f func in that new worker goroutine. The specified name is to identify the worker, it is typically used for debugging purposes.

func (*Stopper) RunWorker

func (s *Stopper) RunWorker(f func())

RunWorker creates a new goroutine and invoke the f func in that new worker goroutine.

func (*Stopper) ShouldStop

func (s *Stopper) ShouldStop() chan struct{}

ShouldStop returns a chan struct{} used for indicating whether the Stop() function has been called on Stopper.

func (*Stopper) Stop

func (s *Stopper) Stop()

Stop signals all managed worker goroutines to stop and wait for them to actually stop.

func (*Stopper) Wait

func (s *Stopper) Wait()

Wait waits on the internal sync.WaitGroup. It only return when all managed worker goroutines are ready to return and called sync.WaitGroup.Done() on the internal sync.WaitGroup.

Jump to

Keyboard shortcuts

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