godropbox: github.com/dropbox/godropbox/sync2 Index | Files | Directories

package sync2

import "github.com/dropbox/godropbox/sync2"

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

Index

Package Files

atomic.go boundedrwlock.go doc.go semaphore.go with.go

func With Uses

func With(mu sync.Locker, f func())

type AtomicDuration Uses

type AtomicDuration int64

func (*AtomicDuration) Add Uses

func (dur *AtomicDuration) Add(dururation time.Duration) time.Duration

func (*AtomicDuration) CompareAndSwap Uses

func (dur *AtomicDuration) CompareAndSwap(oldval, newval time.Duration) (swapped bool)

func (*AtomicDuration) Get Uses

func (dur *AtomicDuration) Get() time.Duration

func (*AtomicDuration) Set Uses

func (dur *AtomicDuration) Set(dururation time.Duration)

type AtomicInt32 Uses

type AtomicInt32 int32

func (*AtomicInt32) Add Uses

func (i32 *AtomicInt32) Add(n int32) int32

func (*AtomicInt32) CompareAndSwap Uses

func (i32 *AtomicInt32) CompareAndSwap(oldval, newval int32) (swapped bool)

func (*AtomicInt32) Get Uses

func (i32 *AtomicInt32) Get() int32

func (*AtomicInt32) Set Uses

func (i32 *AtomicInt32) Set(n int32)

type AtomicInt64 Uses

type AtomicInt64 int64

func (*AtomicInt64) Add Uses

func (i64 *AtomicInt64) Add(n int64) int64

func (*AtomicInt64) CompareAndSwap Uses

func (i64 *AtomicInt64) CompareAndSwap(oldval, newval int64) (swapped bool)

func (*AtomicInt64) Get Uses

func (i64 *AtomicInt64) Get() int64

func (*AtomicInt64) Set Uses

func (i64 *AtomicInt64) Set(n int64)

type AtomicUint32 Uses

type AtomicUint32 uint32

func (*AtomicUint32) Add Uses

func (u32 *AtomicUint32) Add(n uint32) uint32

func (*AtomicUint32) CompareAndSwap Uses

func (u32 *AtomicUint32) CompareAndSwap(oldval, newval uint32) (swapped bool)

func (*AtomicUint32) Get Uses

func (u32 *AtomicUint32) Get() uint32

func (*AtomicUint32) Set Uses

func (u32 *AtomicUint32) Set(n uint32)

type BoundedRWLock Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type Semaphore interface {
    // Increment the semaphore counter by one.
    Release()

    // Decrement the semaphore counter by one, and block if counter < 0
    Acquire()

    // Decrement the semaphore counter by one, and block if counter < 0
    // Wait for up to the given duration.  Returns true if did not timeout
    TryAcquire(timeout time.Duration) bool
}

func NewBoundedSemaphore Uses

func NewBoundedSemaphore(count uint) Semaphore

Create a bounded semaphore. The count parameter must be a positive number. NOTE: The bounded semaphore will panic if the user tries to Release beyond the specified count.

func NewUnboundedSemaphore Uses

func NewUnboundedSemaphore(initialCount int) Semaphore

This returns an unbound counting semaphore with the specified initial count. The semaphore counter can be arbitrary large (i.e., Release can be called unlimited amount of times).

NOTE: In general, users should use bounded semaphore since it is more efficient than unbounded semaphore.

Directories

PathSynopsis
atomic2

Package sync2 imports 5 packages (graph) and is imported by 3 packages. Updated 2018-05-14. Refresh now. Tools for package owners.