filelock

package
v0.0.0-...-028f1de Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLockingError

func IsLockingError(err error) bool

IsLockingError checks whether an error object is os-specific error which represents failure to acquire lock specified

func Lock

func Lock(f File, timeout time.Duration) error

Lock places an advisory write lock on the file, blocking until it can be locked or timing out.

If Lock returns nil, no other process will be able to place a read or write lock on the file until this process exits, closes f, or calls Unlock on it.

If f's descriptor is already read- or write-locked, the behavior of Lock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called when Lock succeeds.

func RLock

func RLock(f File, timeout time.Duration) error

RLock places an advisory read lock on the file, blocking until it can be locked or timing out.

If RLock returns nil, no other process will be able to place a write lock on the file until this process exits, closes f, or calls Unlock on it.

If f is already read- or write-locked, the behavior of RLock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called if RLock succeeds.

func TryLock

func TryLock(f File) error

TryLock places an advisory write lock on the file, but returns immediately when it can not be locked.

If Lock returns nil, no other process will be able to place a read or write lock on the file until this process exits, closes f, or calls Unlock on it.

If f's descriptor is already read- or write-locked, the behavior of Lock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called when Lock succeeds.

func TryRLock

func TryRLock(f File) error

TryRLock places an advisory read lock on the file, but returns immediately when it can not be locked.

If RLock returns nil, no other process will be able to place a write lock on the file until this process exits, closes f, or calls Unlock on it.

If f is already read- or write-locked, the behavior of RLock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called if RLock succeeds.

func Unlock

func Unlock(f File) error

Unlock removes an advisory lock placed on f by this process.

The caller must not attempt to unlock a file that is not locked.

Types

type File

type File interface {
	// Fd returns a valid file descriptor.
	// (If the File is an *os.File, it must not be closed.)
	Fd() uintptr
}

A File provides the minimal set of methods required to lock an open file. File implementations must be usable as map keys. The usual implementation is *os.File.

Jump to

Keyboard shortcuts

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