package semaphore

import "github.com/purpleidea/mgmt/util/semaphore"

Package semaphore contains an implementation of a counting semaphore.

Index

Types

type Semaphore

type Semaphore struct {
	C chan struct{}
	// contains filtered or unexported fields
}

Semaphore is a counting semaphore. It must be initialized before use.

func NewSemaphore

func NewSemaphore(size int) *Semaphore

NewSemaphore creates a new semaphore.

func (*Semaphore) Close

func (obj *Semaphore) Close()

Close shuts down the semaphore and releases all the locks.

func (*Semaphore) Init

func (obj *Semaphore) Init(size int)

Init initializes the semaphore.

func (*Semaphore) P

func (obj *Semaphore) P(n int) error

P acquires n resources.

func (*Semaphore) V

func (obj *Semaphore) V(n int) error

V releases n resources.

Source Files

semaphore.go

Version
v0.0.0-20250322185616-c50a578426f1 (latest)
Published
Mar 22, 2025
Platform
linux/amd64
Imports
1 packages
Last checked
4 days ago

Tools for package owners.