semaphore

package
v0.0.0-...-23e6066 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package semaphore implements System V semaphores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

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

Registry maintains a set of semaphores that can be found by key or ID.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new semaphore set registry.

func (*Registry) FindByID

func (r *Registry) FindByID(id int32) *Set

FindByID looks up a set given an ID.

func (*Registry) FindOrCreate

func (r *Registry) FindOrCreate(ctx context.Context, key, nsems int32, mode linux.FileMode, private, create, exclusive bool) (*Set, error)

FindOrCreate searches for a semaphore set that matches 'key'. If not found, it may create a new one if requested. If private is true, key is ignored and a new set is always created. If create is false, it fails if a set cannot be found. If exclusive is true, it fails if a set with the same key already exists.

func (*Registry) RemoveID

func (r *Registry) RemoveID(id int32, creds *auth.Credentials) error

RemoveID removes set with give 'id' from the registry and marks the set as dead. All waiters will be awakened and fail.

type Set

type Set struct {
	// Id is a handle that identifies the set.
	ID int32
	// contains filtered or unexported fields
}

Set represents a set of semaphores that can be operated atomically.

func (*Set) AbortWait

func (s *Set) AbortWait(num int32, ch chan struct{})

AbortWait notifies that a waiter is giving up and will not wait on the channel anymore.

func (*Set) Change

func (s *Set) Change(ctx context.Context, creds *auth.Credentials, owner fs.FileOwner, perms fs.FilePermissions) error

Change changes some fields from the set atomically.

func (*Set) ExecuteOps

func (s *Set) ExecuteOps(ctx context.Context, ops []linux.Sembuf, creds *auth.Credentials) (chan struct{}, int32, error)

ExecuteOps attempts to execute a list of operations to the set. It only suceeds when all operations can be applied. No changes are made if it fails.

On failure, it may return an error (retries are hopeless) or it may return a channel that can be waited on before attempting again.

func (*Set) GetVal

func (s *Set) GetVal(num int32, creds *auth.Credentials) (int16, error)

GetVal returns a semaphore value.

func (*Set) SetVal

func (s *Set) SetVal(ctx context.Context, num int32, val int16, creds *auth.Credentials) error

SetVal overrides a semaphore value, waking up waiters as needed.

Jump to

Keyboard shortcuts

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