flock

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2015 License: BSD-2-Clause Imports: 2 Imported by: 0

README

Go flock(2) sync.Locker

This is a simple implementation of the sync.Locker interface backed by the flock(2) syscall.

I wouldn't recommend using this in production, but it can be handy if you need a quick inter process lock to prevent concurrent access to shared resources in tests.

Usage

l := flock.NewPath("/tmp/mylock.lock")
l.Lock()
defer l.Unlock()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

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

Lock is an implementation of the sync.Locker interface that is backed by a file flock(2).

func New

func New(f *os.File) *Lock

New returns a new Lock instance using the provided file as the backend.

func NewPath

func NewPath(path string) (*Lock, error)

NewPath first creates the file at the given path, then returns a new Lock instance backed by the file.

func (*Lock) Lock

func (l *Lock) Lock()

Lock aquires a lock on the file using flock(2). Lock will block if the file was previously locked.

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock removes the lock on the file using flock(2).

Jump to

Keyboard shortcuts

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