lock

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lock serializes the writes on one repository and bounds how many run at once.

A lock is held in memory and backed by a file lock on disk, so a second gitd, or one that restarted while the first one's git was still running, waits too. Both are taken before git takes its own `.lock` files, which is what lets a stale one be told from a live one.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("busy")

ErrBusy is a wait that ran out of time or room. A wait the caller gave up on returns the caller's own context error instead, so a cancelled call is not taken for a busy one.

Functions

func ClearStale

func ClearStale(gitDir string, grace time.Duration)

ClearStale removes the `.lock` files git leaves behind when it is killed, from the git directory at gitDir, once they are older than grace.

Only the files git is known to take, never any `*.lock`: something else may own one. It is called with the repository's lock held, so no git of gitd's is running there.

Types

type Locks

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

Locks are the locks of one gitd, one per key, each waited for at most maxWait.

func NewLocks

func NewLocks(dir string, maxWait time.Duration) (*Locks, error)

NewLocks keeps the lock files in dir.

func (*Locks) Acquire

func (locks *Locks) Acquire(parent context.Context, key string) (func(), error)

Acquire waits for key, and returns what releases it.

type Queue

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

Queue bounds how many operations of one kind run at once and how many wait, each for at most maxWait. What does not fit is refused rather than left to pile up.

func NewQueue

func NewQueue(running, queued int, maxWait time.Duration) *Queue

NewQueue lets running operations run and queued more wait.

func (*Queue) Enter

func (queue *Queue) Enter(parent context.Context) (func(), error)

Enter waits for a slot and returns what leaves it, ErrBusy when the queue is full or the wait is too long, or the caller's context error when it gave up.

Jump to

Keyboard shortcuts

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