sync2

package
Version: v0.0.0-...-df3943b Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2014 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

sync2 is a collection of functions meant to supplement the capabilities provided by the standard "sync" package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundedRWLock

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

A fair RWLock with timeouts and a capacity.

Obeys the typical rules about RWLocks

1. If a writer holds the lock, only a single writer is in the lock.
2. If a writer does not hold the lock, any number of readers may hold the
lock.

The lock favors writers, but readers are not starved, and the next batch of readers will be served in before any waiting writers in FIFO order (when a writer releases the lock).

func NewBoundedRWLock

func NewBoundedRWLock(capacity int) *BoundedRWLock

Create a new BoundedRWLock with the given capacity.

RLocks or WLocks beyond this capacity will fail fast with an error.

func (*BoundedRWLock) RLock

func (rw *BoundedRWLock) RLock(timeout time.Duration) (err error)

Wait for a read lock for up to 'timeout'.

Error will be non-nil on timeout or when the wait list is at capacity.

func (*BoundedRWLock) RUnlock

func (rw *BoundedRWLock) RUnlock()

Unlock a read lock.

Should be called only on a goroutine which has gotten a non-error return value from RLock().

func (*BoundedRWLock) WLock

func (rw *BoundedRWLock) WLock(timeout time.Duration) (err error)

Lock for writing, waiting up to 'timeout' for successful exclusive acquisition of the lock.

func (*BoundedRWLock) WUnlock

func (rw *BoundedRWLock) WUnlock()

Unlock the write lock.

Should be called only on a goroutine which has gotten a non-error return value from WLock().

type Semaphore

type Semaphore interface {
	// Increment the semaphore counter by delta
	Increment(delta uint)
	// Decrement the semaphore counter by delta, and block if counter < 0
	Wait(delta uint)
	// Decrement the semaphore counter by delta, and block if counter < 0
	// Wait for up to the given duration.  Returns true if did not timeout
	WaitTimeout(delta uint, timeout time.Duration) bool
}

func NewSemaphore

func NewSemaphore(initialCount int) Semaphore

Jump to

Keyboard shortcuts

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