syncutil

package
v0.0.0-...-8f6cd21 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2016 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

type Mutex struct {
	sync.Mutex
}

A Mutex is a mutual exclusion lock.

type RWMutex

type RWMutex struct {
	sync.RWMutex
}

An RWMutex is a reader/writer mutual exclusion lock.

type TimedMutex

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

TimedMutex is a mutex which dumps a stack trace via the supplied callback whenever a lock is unlocked after having been held for longer than the supplied duration, which must be strictly positive.

func MakeTimedMutex

func MakeTimedMutex(cb TimingFn) TimedMutex

MakeTimedMutex creates a TimedMutex which warns when an Unlock happens more than warnDuration after the corresponding lock. It will use the supplied context and logging callback for the warning message; a nil logger falls back to Fprintf to os.Stderr.

func (*TimedMutex) Lock

func (tm *TimedMutex) Lock()

Lock implements sync.Locker.

func (*TimedMutex) Unlock

func (tm *TimedMutex) Unlock()

Unlock implements sync.Locker.

type TimingFn

type TimingFn func(heldFor time.Duration)

TimingFn is a callback passed to MakeTimedMutex. It is invoked with the measured duration of the critical section of the associated mutex after each Unlock operation.

func ThresholdLogger

func ThresholdLogger(
	ctx context.Context,
	warnDuration time.Duration,
	printf func(context.Context, string, ...interface{}),
	record TimingFn,
) TimingFn

ThresholdLogger returns a timing function which calls 'record' for each measured duration and, for measurements exceeding 'warnDuration', invokes 'printf' with the passed context and a detailed stack trace.

Jump to

Keyboard shortcuts

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