amutex

package
v0.0.0-...-ff2c174 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: Apache-2.0, MIT Imports: 3 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

func Block

func Block(sleeper Sleeper, ch <-chan struct{}) error

Block blocks until either receiving from ch succeeds (in which case it returns nil) or sleeper is interrupted (in which case it returns syserror.ErrInterrupted).

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 = context.Context

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

type Sleeper

type Sleeper = context.ChannelSleeper

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

Jump to

Keyboard shortcuts

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