gxsync

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Overview

ref: https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/

Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.

refers to github.com/jonhoo/drwmutex

Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.

refers to github.com/jonhoo/drwmutex

Package gxsync provides some synchronization primitives such as trylock & semaphore.

Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.

refers to github.com/jonhoo/drwmutex

this file provides a kind of unbouned channel

Index

Constants

View Source
const (
	QSize = 64
)

Variables

View Source
var (
	ErrBroadcastClosed = fmt.Errorf("broadcast closed!")
)

Functions

This section is empty.

Types

type Broadcaster

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

func NewBroadcaster

func NewBroadcaster() Broadcaster

create a new broadcaster object.

func (Broadcaster) Close

func (b Broadcaster) Close()

func (Broadcaster) Listen

func (b Broadcaster) Listen() Receiver

start listening to the nodes.

func (Broadcaster) Write

func (b Broadcaster) Write(value interface{}) (rerr error)

Node a value to all listeners.

type DRWMutex added in v0.3.0

type DRWMutex []paddedRWMutex

drwmutex provides a DRWMutex, a distributed RWMutex for use when there are many readers spread across many cores, and relatively few cores. DRWMutex is meant as an almost drop-in replacement for sync.RWMutex.

func NewDRWMutex added in v0.3.0

func NewDRWMutex() DRWMutex

New returns a new, unlocked, distributed RWMutex.

func (DRWMutex) Lock added in v0.3.0

func (mx DRWMutex) Lock()

Lock takes out an exclusive writer lock similar to sync.Mutex.Lock. A writer lock also excludes all readers.

func (DRWMutex) RLock added in v0.3.0

func (mx DRWMutex) RLock() (l sync.Locker)

RLock takes out a non-exclusive reader lock, and returns the lock that was taken so that it can later be released.

func (DRWMutex) RLocker added in v0.3.0

func (mx DRWMutex) RLocker() sync.Locker

RLocker returns a sync.Locker presenting Lock() and Unlock() methods that take and release a non-exclusive *reader* lock. Note that this call may be relatively slow, depending on the underlying system architechture, and so its result should be cached if possible.

func (DRWMutex) Unlock added in v0.3.0

func (mx DRWMutex) Unlock()

Unlock releases an exclusive writer lock similar to sync.Mutex.Unlock.

type Empty

type Empty struct{}

type Mutex added in v0.3.0

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

Mutex is simple sync.Mutex + ability to try to Lock.

func (*Mutex) IsLocked added in v0.3.0

func (m *Mutex) IsLocked() bool

IsLocked returns the lock state

func (*Mutex) Lock added in v0.3.0

func (m *Mutex) Lock()

Lock locks m. If the lock is already in use, the calling goroutine blocks until the mutex is available.

func (*Mutex) TryLock added in v0.3.0

func (m *Mutex) TryLock() bool

TryLock tries to lock m. It returns true in case of success, false otherwise.

func (*Mutex) Unlock added in v0.3.0

func (m *Mutex) Unlock()

Unlock unlocks m. It is a run-time error if m is not locked on entry to Unlock.

A locked Mutex is not associated with a particular goroutine. It is allowed for one goroutine to lock a Mutex and then arrange for another goroutine to unlock it.

type Node

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

type Once added in v0.3.0

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

Once is an object that will perform exactly one action until Reset is called. refer from github.com/matryer/resync

func (*Once) Do added in v0.3.0

func (o *Once) Do(f func())

Do simulates sync.Once.Do by executing the specified function only once, until Reset is called. See http://golang.org/pkg/sync/#Once

func (*Once) Reset added in v0.3.0

func (o *Once) Reset()

Reset indicates that the next call to Do should actually be called once again.

type Receiver

type Receiver struct {
	C chan Node
}

func (*Receiver) Read

func (r *Receiver) Read() (interface{}, error)

read a value that has been broadcast, waiting until one is available if necessary.

func (*Receiver) ReadChan

func (r *Receiver) ReadChan() chan Node

func (*Receiver) ReadDone

func (r *Receiver) ReadDone(n Node) (interface{}, error)

type Semaphore

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

func NewSemaphore

func NewSemaphore(parallelNum int) *Semaphore

func (*Semaphore) Post

func (s *Semaphore) Post()

func (*Semaphore) TimeWait

func (s *Semaphore) TimeWait(timeout int) bool

@timeout is in nanoseconds

func (*Semaphore) TryWait

func (s *Semaphore) TryWait() bool

func (*Semaphore) Wait

func (s *Semaphore) Wait()

type UnboundedChan

type UnboundedChan struct {

	// Q      *gxqueue.Queue
	Q *gxdeque.Deque
	// contains filtered or unexported fields
}

refer from redisgo/redis/pool.go

func NewUnboundedChan

func NewUnboundedChan() *UnboundedChan

func (*UnboundedChan) Close

func (q *UnboundedChan) Close()

func (*UnboundedChan) Len

func (q *UnboundedChan) Len() int

func (*UnboundedChan) Pop

func (q *UnboundedChan) Pop() interface{}

func (*UnboundedChan) Push

func (q *UnboundedChan) Push(v interface{})

func (*UnboundedChan) SetWaitOption

func (q *UnboundedChan) SetWaitOption(wait bool)

在pop时,如果没有资源,是否等待 即使用乐观锁还是悲观锁

func (*UnboundedChan) TryPop

func (q *UnboundedChan) TryPop() (interface{}, bool)

Directories

Path Synopsis
Package gxatomic provides simple wrappers around numerics to enforce atomic access.
Package gxatomic provides simple wrappers around numerics to enforce atomic access.
Package gxerrgroup implements an actor-runner with deterministic teardown.
Package gxerrgroup implements an actor-runner with deterministic teardown.
Package pool implements a pool of Object interfaces to manage and reuse them.
Package pool implements a pool of Object interfaces to manage and reuse them.

Jump to

Keyboard shortcuts

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