lock

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2015 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package lock implements simple locking primitives on a directory using flock

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLocked     = errors.New("directory already locked")
	ErrNotExist   = errors.New("directory does not exist")
	ErrPermission = errors.New("permission denied")
)

Functions

This section is empty.

Types

type DirLock

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

DirLock represents a lock on a directory

func ExclusiveLock

func ExclusiveLock(dir string) (*DirLock, error)

ExclusiveLock takes an exclusive lock on a directory. It will block if an exclusive lock is already held on the directory.

func NewLock

func NewLock(dir string) (*DirLock, error)

NewLock opens a new lock on a directory without acquisition

func SharedLock

func SharedLock(dir string) (*DirLock, error)

SharedLock takes a co-operative (shared) lock on a directory. It will block if an exclusive lock is already held on the directory.

func TryExclusiveLock

func TryExclusiveLock(dir string) (*DirLock, error)

TryExclusiveLock takes an exclusive lock on a directory without blocking. It will return ErrLocked if any lock is already held on the directory.

func TrySharedLock

func TrySharedLock(dir string) (*DirLock, error)

TrySharedLock takes a co-operative (shared) lock on a directory without blocking. It will return ErrLocked if an exclusive lock already exists on the directory.

func (*DirLock) Close

func (l *DirLock) Close() error

Close closes the lock which implicitly unlocks it as well

func (*DirLock) ExclusiveLock

func (l *DirLock) ExclusiveLock() error

ExclusiveLock takes an exclusive lock on a directory. This is idempotent when the DirLock already represents an exclusive lock, and promotes a shared lock to exclusive atomically. It will block if an exclusive lock is already held on the directory.

func (*DirLock) Fd

func (l *DirLock) Fd() (int, error)

Fd returns the lock's file descriptor, or an error if the lock is closed

func (*DirLock) SharedLock

func (l *DirLock) SharedLock() error

SharedLock takes a co-operative (shared) lock on a directory. This is idempotent when the DirLock already represents a shared lock, and demotes an exclusive lock to shared atomically. It will block if an exclusive lock is already held on the directory.

func (*DirLock) TryExclusiveLock

func (l *DirLock) TryExclusiveLock() error

TryExclusiveLock takes an exclusive lock on a directory without blocking. This is idempotent when the DirLock already represents an exclusive lock, and tries promote a shared lock to exclusive atomically. It will return ErrLocked if any lock is already held on the directory.

func (*DirLock) TrySharedLock

func (l *DirLock) TrySharedLock() error

TrySharedLock takes a co-operative (shared) lock on a directory without blocking. This is idempotent when the DirLock already represents a shared lock, and tries demote an exclusive lock to shared atomically. It will return ErrLocked if an exclusive lock already exists on the directory.

func (*DirLock) Unlock

func (l *DirLock) Unlock() error

Unlock unlocks the lock

Jump to

Keyboard shortcuts

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