lockfile

package
v1.14.7 Latest Latest
Warning

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

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

Documentation

Overview

SPDX-License-Identifier: Apache-2.0 Copyright Authors of Cilium

Index

Constants

View Source
const (
	SETLK  = 37 // F_OFD_SETLK
	SETLKW = 38 // F_OFD_SETLKW
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Lockfile

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

Lockfile is a simple wrapper around POSIX file locking but it uses Linux's per-fd locks, which makes it safe to use within the same process

func NewLockfile

func NewLockfile(path string) (*Lockfile, error)

NewLockfile creates and opens a lockfile, but does not acquire a lock.

func (*Lockfile) Close

func (l *Lockfile) Close() error

Close will close the file, which implicitly removes all locks held. It is an error to re-use a closed Lockfile.

func (*Lockfile) Lock

func (l *Lockfile) Lock(ctx context.Context, exclusive bool) error

Lock will attempt to take a lock, blocking until it is able to do so. If exclusive is true, then it will obtain a write, or exclusive, lock

func (*Lockfile) TryLock

func (l *Lockfile) TryLock(exclusive bool) error

TryLock will attempt to take a lock, returining error if it is not possible to acquire the lock. If exclusive is true, then it will attempt to obtain a write, or exclusive, lock

func (*Lockfile) Unlock

func (l *Lockfile) Unlock() error

Unlock removes the lock, but keeps the file open.

Jump to

Keyboard shortcuts

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