flock

package
v0.0.0-...-6c7272e Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package flock has helper code for managing inter-processes locks through temporary files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReleaseAllLocks

func ReleaseAllLocks() error

ReleaseAllLocks releases all the FLocks by removing all the underlying files.

Types

type Mutex

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

Mutex is a file based inter-process mutex. Mutex should only be created by New, Lock or TryLock.

func Lock

func Lock(n string) *Mutex

Lock creates a Mutex by using a file named with the given strings, and acquires the inter-process lock, then returns the created Mutex. This is a blocking call and the returned Mutex is guaranteed to hold the lock.

func New

func New(n string) *Mutex

New creates a new file based inter-process mutex which uses the given string as the name of the underlying file. The Mutex created by New does not hold any lock.

func TryLock

func TryLock(n string) *Mutex

TryLock creates a Mutex by using a file named with the given string, and tries to acquire the inter-process lock, then returns the created Mutex. This is a non-blocking call. The returned Mutex may not hold the lock, and should be checked with Locked() to tell if the locked is held by the Mutex.

func (*Mutex) Lock

func (m *Mutex) Lock()

Lock acquires the inter-process lock in a blocking way, it only returns when it has acquired the lock. Panic if the Mutex already holds the lock when calling this function.

func (*Mutex) Locked

func (m *Mutex) Locked() bool

Locked returns true if the Mutex holds the lock and valid to call Unlock, false if the Mutex does not hold the lock and valid to call TryLock or Lock. The state of locked/unlocked can only be changed by calling Lock, TryLock and Unlock functions, removing/modifing the underlying files does not change this state.

func (*Mutex) TryLock

func (m *Mutex) TryLock() bool

TryLock acquires the inter-process lock in a non-blocking way. Returns true if the lock is now held by the Mutex, or false if not. Panic if the Mutex already holds the lock.

func (*Mutex) Unlock

func (m *Mutex) Unlock() bool

Unlock releases the inter-process lock, returns true if the lock is released successfully, false otherwise. Panic if the Mutex has already been unlocked.

Jump to

Keyboard shortcuts

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