syncutil

package
v0.0.0-...-1b7ac2d Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2014 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package syncutil provides various concurrency mechanisms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoroutineID

func GoroutineID() int64

Types

type Gate

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

A Gate limits concurrency.

func NewGate

func NewGate(max int) *Gate

NewGate returns a new gate that will only permit max operations at once.

func (*Gate) Done

func (g *Gate) Done()

Done finishes an operation.

func (*Gate) Start

func (g *Gate) Start()

Start starts an operation, blocking until the gate has room.

type Group

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

A Group is like a sync.WaitGroup and coordinates doing multiple things at once. Its zero value is ready to use.

func (*Group) Err

func (g *Group) Err() error

Err waits for all previous calls to Go to complete and returns the first non-nil error, or nil.

func (*Group) Errs

func (g *Group) Errs() []error

Errs waits for all previous calls to Go to complete and returns all non-nil errors.

func (*Group) Go

func (g *Group) Go(fn func() error)

Go runs fn in its own goroutine, but does not wait for it to complete. Call Err or Errs to wait for all the goroutines to complete.

func (*Group) Wait

func (g *Group) Wait()

Wait waits for all the previous calls to Go to complete.

type RWMutexTracker

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

RWMutexTracker is a sync.RWMutex that tracks who owns the current exclusive lock. It's used for debugging deadlocks.

func (*RWMutexTracker) Holder

func (m *RWMutexTracker) Holder() string

Holder returns the stack trace of the current exclusive lock holder's stack when it acquired the lock (with Lock). It returns the empty string if the lock is not currently held.

func (*RWMutexTracker) Lock

func (m *RWMutexTracker) Lock()

func (*RWMutexTracker) RLock

func (m *RWMutexTracker) RLock()

func (*RWMutexTracker) RUnlock

func (m *RWMutexTracker) RUnlock()

func (*RWMutexTracker) Unlock

func (m *RWMutexTracker) Unlock()

type Sem

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

Sem implements a semaphore that can have multiple units acquired/released at a time.

func NewSem

func NewSem(max int64) *Sem

NewSem creates a semaphore with max units available for acquisition.

func (*Sem) Acquire

func (s *Sem) Acquire(n int64) error

Acquire will deduct n units from the semaphore. If the deduction would result in the available units falling below zero, the call will block until another go routine returns units via a call to Release. If more units are requested than the semaphore is configured to hold, error will be non-nil.

func (*Sem) Release

func (s *Sem) Release(n int64)

Release will return n units to the semaphore and notify any currently blocking Acquire calls.

Jump to

Keyboard shortcuts

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