filelock

package
v0.0.0-...-436d200 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

FileLock object can be used to create locks that can be used to synchronise different processes running on the same machine.

The current implementation of FileLock will always release all acquired locks once the process itself exits.

In order to reduce syscall overhead/complexity, this does not implement a fair lock. In particular, flock is reader-preferred and may starve writers. If you require fairness, you can implement it on top of this interface using multiple FileLocks.

NOTE: FileLock is not thread safe, since it is not meant to be used from multiple threads but from different processes instead!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHeldElsewhere

func IsHeldElsewhere(err error) bool

Returns whether the error returned by TryLock/TryRLock is the result of the lock already being held by another process.

Types

type FileLock

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

func New

func New(name string) *FileLock

Creates new FileLock object given a unique name.

func (*FileLock) Lock

func (f *FileLock) Lock() error

Blocking way to acquire an exclusive lock.

func (*FileLock) RLock

func (f *FileLock) RLock() error

Blocking way to acquire a shared lock.

func (*FileLock) RUnlock

func (f *FileLock) RUnlock() error

Unlocks the shared lock. If the Lock was never acquired before or if the Lock was acquired but was not shared, it will return an error.

func (*FileLock) TryLock

func (f *FileLock) TryLock() error

Non blocking way to try to acquire an exclusive lock.

func (*FileLock) TryRLock

func (f *FileLock) TryRLock() error

Non blocking way to try to acquire a shared lock.

func (*FileLock) Unlock

func (f *FileLock) Unlock() error

Unlocks the exclusive lock. If the Lock was never acquired before or if the Lock was acquired but was not exclusive, it will return an error.

Jump to

Keyboard shortcuts

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