lock

package
v0.0.0-...-03dfc37 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package lock - implements filesystem locking wrappers around an open file descriptor.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyLocked is returned if the underlying fd is already locked.
	ErrAlreadyLocked = errors.New("file already locked")
)

Functions

func Open

func Open(path string, flag int, perm os.FileMode) (*os.File, error)

Open - Call os.OpenFile

Types

type LockedFile

type LockedFile struct {
	*os.File
}

LockedFile represents a locked file

func LockedOpenFile

func LockedOpenFile(path string, flag int, perm os.FileMode) (*LockedFile, error)

LockedOpenFile - initializes a new lock and protects the file from concurrent access across mount points. This implementation doesn't support all the open flags and shouldn't be considered as replacement for os.OpenFile().

func TryLockedOpenFile

func TryLockedOpenFile(path string, flag int, perm os.FileMode) (*LockedFile, error)

TryLockedOpenFile - tries a new write lock, functionality it is similar to LockedOpenFile with with syscall.LOCK_EX mode but along with syscall.LOCK_NB such that the function doesn't wait forever but instead returns if it cannot acquire a write lock.

type RLockedFile

type RLockedFile struct {
	*LockedFile
	// contains filtered or unexported fields
}

RLockedFile represents a read locked file, implements a special closer which only closes the associated *os.File when the ref count. has reached zero, i.e when all the readers have given up their locks.

func RLockedOpenFile

func RLockedOpenFile(path string) (*RLockedFile, error)

RLockedOpenFile - returns a wrapped read locked file, if the file doesn't exist at path returns an error.

func (*RLockedFile) Close

func (r *RLockedFile) Close() (err error)

Close - this closer implements a special closer closes the underlying fd only when the refs reach zero.

func (*RLockedFile) IncLockRef

func (r *RLockedFile) IncLockRef()

IncLockRef - is used by called to indicate lock refs.

func (*RLockedFile) IsClosed

func (r *RLockedFile) IsClosed() bool

IsClosed - Check if the rlocked file is already closed.

Jump to

Keyboard shortcuts

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