go-vitess.v1: gopkg.in/src-d/go-vitess.v1/sync2 Index | Files

package sync2

import "gopkg.in/src-d/go-vitess.v1/sync2"

Package sync2 provides extra functionality along the same lines as sync.

Index

Package Files

atomic.go batcher.go consolidator.go doc.go semaphore.go

type AtomicBool Uses

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

AtomicBool gives an atomic boolean variable.

func NewAtomicBool Uses

func NewAtomicBool(n bool) AtomicBool

NewAtomicBool initializes a new AtomicBool with a given value.

func (*AtomicBool) CompareAndSwap Uses

func (i *AtomicBool) CompareAndSwap(o, n bool) bool

CompareAndSwap atomatically swaps the old with the new value.

func (*AtomicBool) Get Uses

func (i *AtomicBool) Get() bool

Get atomically returns the current value.

func (*AtomicBool) Set Uses

func (i *AtomicBool) Set(n bool)

Set atomically sets n as new value.

type AtomicDuration Uses

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

AtomicDuration is a wrapper with a simpler interface around atomic.(Add|Store|Load|CompareAndSwap)Int64 functions.

func NewAtomicDuration Uses

func NewAtomicDuration(duration time.Duration) AtomicDuration

NewAtomicDuration initializes a new AtomicDuration with a given value.

func (*AtomicDuration) Add Uses

func (d *AtomicDuration) Add(duration time.Duration) time.Duration

Add atomically adds duration to the value.

func (*AtomicDuration) CompareAndSwap Uses

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

CompareAndSwap atomatically swaps the old with the new value.

func (*AtomicDuration) Get Uses

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

Get atomically returns the current value.

func (*AtomicDuration) Set Uses

func (d *AtomicDuration) Set(duration time.Duration)

Set atomically sets duration as new value.

type AtomicInt32 Uses

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

AtomicInt32 is a wrapper with a simpler interface around atomic.(Add|Store|Load|CompareAndSwap)Int32 functions.

func NewAtomicInt32 Uses

func NewAtomicInt32(n int32) AtomicInt32

NewAtomicInt32 initializes a new AtomicInt32 with a given value.

func (*AtomicInt32) Add Uses

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

Add atomically adds n to the value.

func (*AtomicInt32) CompareAndSwap Uses

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

CompareAndSwap atomatically swaps the old with the new value.

func (*AtomicInt32) Get Uses

func (i *AtomicInt32) Get() int32

Get atomically returns the current value.

func (*AtomicInt32) Set Uses

func (i *AtomicInt32) Set(n int32)

Set atomically sets n as new value.

type AtomicInt64 Uses

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

AtomicInt64 is a wrapper with a simpler interface around atomic.(Add|Store|Load|CompareAndSwap)Int64 functions.

func NewAtomicInt64 Uses

func NewAtomicInt64(n int64) AtomicInt64

NewAtomicInt64 initializes a new AtomicInt64 with a given value.

func (*AtomicInt64) Add Uses

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

Add atomically adds n to the value.

func (*AtomicInt64) CompareAndSwap Uses

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

CompareAndSwap atomatically swaps the old with the new value.

func (*AtomicInt64) Get Uses

func (i *AtomicInt64) Get() int64

Get atomically returns the current value.

func (*AtomicInt64) Set Uses

func (i *AtomicInt64) Set(n int64)

Set atomically sets n as new value.

type AtomicString Uses

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

AtomicString gives you atomic-style APIs for string, but it's only a convenience wrapper that uses a mutex. So, it's not as efficient as the rest of the atomic types.

func (*AtomicString) CompareAndSwap Uses

func (s *AtomicString) CompareAndSwap(oldval, newval string) (swqpped bool)

CompareAndSwap atomatically swaps the old with the new value.

func (*AtomicString) Get Uses

func (s *AtomicString) Get() string

Get atomically returns the current value.

func (*AtomicString) Set Uses

func (s *AtomicString) Set(str string)

Set atomically sets str as new value.

type Batcher Uses

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

Batcher delays concurrent operations for a configurable interval in order to batch them up or otherwise clock their operation to run concurrently.

It is implemented as a channel of int32s. Each waiter blocks on the channel from which it gets a sequentially increasing batch ID when the timer elapses.

Hence a waiter is delayed for at most the batch interval.

func NewBatcher Uses

func NewBatcher(interval time.Duration) *Batcher

NewBatcher returns a new Batcher

func (*Batcher) Wait Uses

func (b *Batcher) Wait() int

Wait adds a new waiter to the queue and blocks until the next batch

type Consolidator Uses

type Consolidator struct {
    *ConsolidatorCache
    // contains filtered or unexported fields
}

Consolidator consolidates duplicate queries from executing simulaneously and shares results between them.

func NewConsolidator Uses

func NewConsolidator() *Consolidator

NewConsolidator creates a new Consolidator

func (*Consolidator) Create Uses

func (co *Consolidator) Create(query string) (r *Result, created bool)

Create adds a query to currently executing queries and acquires a lock on its Result if it is not already present. If the query is a duplicate, Create returns false.

type ConsolidatorCache Uses

type ConsolidatorCache struct {
    *cache.LRUCache
}

ConsolidatorCache is a thread-safe object used for counting how often recent queries have been consolidated. It is also used by the txserializer package to count how often transactions have been queued and had to wait because they targeted the same row (range).

func NewConsolidatorCache Uses

func NewConsolidatorCache(capacity int64) *ConsolidatorCache

NewConsolidatorCache creates a new cache with the given capacity.

func (*ConsolidatorCache) Items Uses

func (cc *ConsolidatorCache) Items() []ConsolidatorCacheItem

Items returns the items in the cache as an array of String, int64 structs

func (*ConsolidatorCache) Record Uses

func (cc *ConsolidatorCache) Record(query string)

Record increments the count for "query" by 1. If it's not in the cache yet, it will be added.

type ConsolidatorCacheItem Uses

type ConsolidatorCacheItem struct {
    Query string
    Count int64
}

ConsolidatorCacheItem is a wrapper for the items in the consolidator cache

type Result Uses

type Result struct {
    Result interface{}
    Err    error
    // contains filtered or unexported fields
}

Result is a wrapper for result of a query.

func (*Result) Broadcast Uses

func (rs *Result) Broadcast()

Broadcast removes the entry from current queries and releases the lock on its Result. Broadcast should be invoked when original query completes execution.

func (*Result) Wait Uses

func (rs *Result) Wait()

Wait waits for the original query to complete execution. Wait should be invoked for duplicate queries.

type Semaphore Uses

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

Semaphore is a counting semaphore with the option to specify a timeout.

func NewSemaphore Uses

func NewSemaphore(count int, timeout time.Duration) *Semaphore

NewSemaphore creates a Semaphore. The count parameter must be a positive number. A timeout of zero means that there is no timeout.

func (*Semaphore) Acquire Uses

func (sem *Semaphore) Acquire() bool

Acquire returns true on successful acquisition, and false on a timeout.

func (*Semaphore) Release Uses

func (sem *Semaphore) Release()

Release releases the acquired semaphore. You must not release more than the number of semaphores you've acquired.

func (*Semaphore) Size Uses

func (sem *Semaphore) Size() int

Size returns the current number of available slots.

func (*Semaphore) TryAcquire Uses

func (sem *Semaphore) TryAcquire() bool

TryAcquire acquires a semaphore if it's immediately available. It returns false otherwise.

Package sync2 imports 4 packages (graph) and is imported by 41 packages. Updated 2019-06-13. Refresh now. Tools for package owners.