GithubHelp home page GithubHelp logo

isabella232 / mutex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juju/mutex

0.0 0.0 0.0 41 KB

Provides a named machine level mutex shareable between processes.

License: Other

Go 97.99% Makefile 2.01%

mutex's Introduction

mutex

import "github.com/juju/mutex/v2"

Overview

package mutex provides a named machine level mutex shareable between processes. GoDoc

Mutexes have names. Each each name, only one mutex for that name can be acquired at the same time, within and across process boundaries. If a process dies while the mutex is held, the mutex is automatically released.

The Linux/MacOS implementation uses flock, while the Windows implementation uses a named mutex.

Index

Package files

doc.go errors.go legacy_mutex_linux.go mutex.go mutex_flock.go

Variables

var (
    ErrTimeout   = errors.New("timeout acquiring mutex")
    ErrCancelled = errors.New("cancelled acquiring mutex")
)

type Clock

type Clock interface {
    // After waits for the duration to elapse and then sends the
    // current time on the returned channel.
    After(time.Duration) <-chan time.Time

    // Now returns the current clock time.
    Now() time.Time
}

Clock provides an interface for dealing with clocks.

type Releaser

type Releaser interface {
    // Release releases the mutex. Release may be called multiple times, but
    // only the first call will release this instance of the mutex. Release is
    // unable to release the mutex successfully it will call panic to forcibly
    // release the mutex.
    Release()
}

Releaser defines the Release method that is the only thing that can be done to a acquired mutex.

func Acquire

func Acquire(spec Spec) (Releaser, error)

Acquire will attempt to acquire the named mutex. If the Timout value is hit, ErrTimeout is returned. If the Cancel channel is signalled, ErrCancelled is returned.

type Spec

type Spec struct {
    // Name is required, and must start with a letter and contain at most
    // 40 letters, numbers or dashes.
    Name string

    // Clock must be provided and is exposed for testing purposes.
    Clock Clock

    // Delay defines how often to check for lock acquisition, for
    // compatibility code that requires polling.
    Delay time.Duration

    // Timeout allows the caller to specify how long to wait. If Timeout
    // is zero, then the call will block forever.
    Timeout time.Duration

    // Cancel if signalled will cause the Acquire method to return with ErrCancelled.
    Cancel <-chan struct{}
}

Spec defines the name of the mutex and behaviour of the Acquire function.

func (*Spec) Validate

func (s *Spec) Validate() error

Validate checks the attributes of Spec for validity.


Generated by godoc2md

mutex's People

Contributors

axw avatar howbazaar avatar jameinel avatar jujubot avatar simonrichardson avatar wallyworld avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.