taskcluster-worker: github.com/taskcluster/taskcluster-worker/runtime/atomics Index | Files

package atomics

import "github.com/taskcluster/taskcluster-worker/runtime/atomics"

Package atomics provides types that can be concurrently accessed and modified, without caller code needing to implement locking.


Package Files

bool.go doc.go once.go waitgroup.go


var ErrWaitGroupDraining = errors.New(
    "WaitGroup is draining, internal counter can no-longer be incremented",

ErrWaitGroupDraining is returned from WaitGroup.Add(), if WaitGroup is in draining state.

type Bool Uses

type Bool struct {
    // contains filtered or unexported fields

Bool is an atomic boolean, no need for locking which makes the code faster and simpler.

This interface is really just to abstract away the 0 or 1 value of an int32 modified using the sync/atomic package. Hopefully the go compiler will inline these methods so they'll be super fast.

func NewBool Uses

func NewBool(value bool) Bool

NewBool returns an atomics.Bool initialized with value.

Note it is perfectly safe to just declare an atomics.Bool; it defaults to false just like a normal boolean would do.

func (*Bool) Get Uses

func (b *Bool) Get() bool

Get returns the value of the boolean

func (*Bool) Set Uses

func (b *Bool) Set(value bool)

Set sets the value of the boolean to true or false

func (*Bool) Swap Uses

func (b *Bool) Swap(value bool) bool

Swap sets the value of the boolean to true or false and returns the old value

type Once Uses

type Once struct {
    // contains filtered or unexported fields

Once is similar to sync.Done except that once.Do() returns true, if this was the first call to once.Do(). Additionally, a methods once.Wait(), once.Done(), and once.IsDone() have been added for anyone waiting for this once.Do() to have been called.

Also once.Do(nil) will not panic, but act similar to once.Do(func(){}).

func (*Once) Do Uses

func (o *Once) Do(f func()) bool

Do will call f() and return true, the first time once.Do() is called. All following callls to once.Do() will not call f() and return false.

func (*Once) Done Uses

func (o *Once) Done() <-chan struct{}

Done returns a channel that is closed when once.Do(fn) have been called and fn() has returned.

func (*Once) IsDone Uses

func (o *Once) IsDone() bool

IsDone returns true, if once.Do() have been called, this is non-blocking.

This is just short-hand for non-blocking select on once.Done().

func (*Once) Wait Uses

func (o *Once) Wait()

Wait will block until once.Do() have been called, and this call has returned. After first once.Do() call once.Wait() will always return immediately.

This is just short-hand for <-once.Done().

type WaitGroup Uses

type WaitGroup struct {
    // contains filtered or unexported fields

WaitGroup is similar to sync.WaitGroup, except it can enter a draining state at which point additional calls to Add will fail and returns ErrWaitGroupDraining

func (*WaitGroup) Add Uses

func (wg *WaitGroup) Add(delta int) error

Add will increment internal counter by delta, if not in draining state. If draining, Add(delta) return ErrWaitGroupDraining if delta is positive.

If the internal counter goes negative Add will panic.

func (*WaitGroup) Done Uses

func (wg *WaitGroup) Done()

Done decrements internal counter and unblocks Wait() when it counter reaches zero.

If the internal counter goes negative Done will panic.

func (*WaitGroup) Drain Uses

func (wg *WaitGroup) Drain()

Drain prevents additional increments using Add(delta)

func (*WaitGroup) String Uses

func (wg *WaitGroup) String() string

String returns a string representation of the WaitGroup useful for debugging

func (*WaitGroup) Wait Uses

func (wg *WaitGroup) Wait()

Wait blocks until internal counter reaches zero.

func (*WaitGroup) WaitAndDrain Uses

func (wg *WaitGroup) WaitAndDrain()

WaitAndDrain will wait for the internal counter to reach zero and atomically switch to draining mode, so additional Add() calls will fail.

Package atomics imports 4 packages (graph) and is imported by 15 packages. Updated 2017-04-20. Refresh now. Tools for package owners.