semaphores

package
v0.0.0-...-a9ff0e8 Latest Latest
Warning

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

Go to latest
Published: May 13, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package semaphores provides a go implementation of binary and counting semaphores. The underlying implementation is built on the channel primitive for goroutine notifications and atomic operations for for the fast path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Semaphore

type Semaphore interface {
	// Take (decrement) a semaphore.  Routine will block until the semaphore is available.
	Take()

	// Take (decrement) a semaphore.  Routine will block until the timeout has occurred
	// or the semaphore becomes available
	TryTake(timeout time.Duration) bool

	// Release (increment) the semaphore.  Returns false if semaphore is signal.
	Give() bool

	// Test if the semaphore is signal.
	IsFull() bool

	// Test if the semaphore is empty.
	IsEmpty() bool

	//  Returns the count of a semaphore.
	Count() int32
}

Semaphore interface.

func MakeBinarySemaphore

func MakeBinarySemaphore(full bool) Semaphore

Create a binary semaphore. The semaphore can be initialized to 'up' (signal) or 'down'.

func MakeCountingSemaphore

func MakeCountingSemaphore(initial int32, max int32) Semaphore

Create a counting semaphore. The give operation increments the semaphore. A take operation decrements the semaphore.

Jump to

Keyboard shortcuts

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