amutex

package
v0.0.0-...-23e6066 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package amutex provides the implementation of an abortable mutex. It allows the Lock() function to be canceled while it waits to acquire the mutex.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbortableMutex

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

AbortableMutex is an abortable mutex. It allows Lock() to be aborted while it waits to acquire the mutex.

func (*AbortableMutex) Init

func (m *AbortableMutex) Init()

Init initializes the abortable mutex.

func (*AbortableMutex) Lock

func (m *AbortableMutex) Lock(s Sleeper) bool

Lock attempts to acquire the mutex, returning true on success. If something is written to the "c" while Lock waits, the wait is aborted and false is returned instead.

func (*AbortableMutex) Unlock

func (m *AbortableMutex) Unlock()

Unlock releases the mutex.

type NoopSleeper

type NoopSleeper struct{}

NoopSleeper is a stateless no-op implementation of Sleeper for anonymous embedding in other types that do not support cancelation.

func (NoopSleeper) SleepFinish

func (NoopSleeper) SleepFinish(success bool)

SleepFinish implements Sleeper.SleepFinish.

func (NoopSleeper) SleepStart

func (NoopSleeper) SleepStart() <-chan struct{}

SleepStart implements Sleeper.SleepStart.

type Sleeper

type Sleeper interface {
	// SleepStart is called by the AbortableMutex.Lock() function when the
	// mutex is contended and the goroutine is about to sleep.
	//
	// A channel can be returned that causes the sleep to be canceled if
	// it's readable. If no cancelation is desired, nil can be returned.
	SleepStart() <-chan struct{}

	// SleepFinish is called by AbortableMutex.Lock() once a contended mutex
	// is acquired or the wait is aborted.
	SleepFinish(success bool)
}

Sleeper must be implemented by users of the abortable mutex to allow for cancelation of waits.

Jump to

Keyboard shortcuts

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