grpool

package
v1.1.12 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package glist provides a concurrent-safe/unsafe doubly linked list.

Package grpool implements a goroutine reusable pool.

Package rwmutex provides switch of concurrent safe feature for sync.RWMutex.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(f func()) error

Add pushes a new job to the pool using default goroutine pool. The job will be executed asynchronously.

func Jobs

func Jobs() int

Jobs returns current job count of default goroutine pool.

func Size

func Size() int

Size returns current goroutine count of default goroutine pool.

Types

type Bool

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

func NewBool

func NewBool(value ...bool) *Bool

NewBool returns a concurrent-safe object for bool type, with given initial value <value>.

func (*Bool) Cas

func (v *Bool) Cas(old, new bool) bool

Cas executes the compare-and-swap operation for value.

func (*Bool) Clone

func (v *Bool) Clone() *Bool

Clone clones and returns a new concurrent-safe object for bool type.

func (*Bool) Set

func (v *Bool) Set(value bool) (old bool)

Set atomically stores <value> into t.value and returns the previous value of t.value.

func (*Bool) String

func (v *Bool) String() string

String implements String interface for string printing.

func (*Bool) Val

func (v *Bool) Val() bool

Val atomically loads t.valueue.

type Element

type Element = list.Element

type Int

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

func NewInt

func NewInt(value ...int) *Int

NewInt returns a concurrent-safe object for int type, with given initial value <value>.

func (*Int) Add

func (v *Int) Add(delta int) (new int)

Add atomically adds <delta> to t.value and returns the new value.

func (*Int) Cas

func (v *Int) Cas(old, new int) bool

Cas executes the compare-and-swap operation for value.

func (*Int) Clone

func (v *Int) Clone() *Int

Clone clones and returns a new concurrent-safe object for int type.

func (*Int) Set

func (v *Int) Set(value int) (old int)

Set atomically stores <value> into t.value and returns the previous value of t.value.

func (*Int) String

func (v *Int) String() string

String implements String interface for string printing.

func (*Int) Val

func (v *Int) Val() int

Val atomically loads t.value.

type List

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

func NewFrom

func NewFrom(array []interface{}, safe ...bool) *List

NewFrom creates and returns a list from a copy of given slice <array>. The parameter <safe> used to specify whether using list in concurrent-safety, which is false in default.

func NewList

func NewList(safe ...bool) *List

New creates and returns a new empty doubly linked list.

func (*List) Back

func (l *List) Back() (e *Element)

Back returns the last element of list <l> or nil if the list is empty.

func (*List) BackAll

func (l *List) BackAll() (values []interface{})

BackAll copies and returns values of all elements from back of <l> as slice.

func (*List) BackValue

func (l *List) BackValue() (value interface{})

BackValue returns value of the last element of <l> or nil if the list is empty.

func (*List) Clear

func (l *List) Clear()

See RemoveAll().

func (*List) Front

func (l *List) Front() (e *Element)

Front returns the first element of list <l> or nil if the list is empty.

func (*List) FrontAll

func (l *List) FrontAll() (values []interface{})

FrontAll copies and returns values of all elements from front of <l> as slice.

func (*List) FrontValue

func (l *List) FrontValue() (value interface{})

FrontValue returns value of the first element of <l> or nil if the list is empty.

func (*List) InsertAfter

func (l *List) InsertAfter(p *Element, v interface{}) (e *Element)

InsertAfter inserts a new element <e> with value <v> immediately after <p> and returns <e>. If <p> is not an element of <l>, the list is not modified. The <p> must not be nil.

func (*List) InsertBefore

func (l *List) InsertBefore(p *Element, v interface{}) (e *Element)

InsertBefore inserts a new element <e> with value <v> immediately before <p> and returns <e>. If <p> is not an element of <l>, the list is not modified. The <p> must not be nil.

func (*List) Iterator

func (l *List) Iterator(f func(e *Element) bool)

Iterator is alias of IteratorAsc.

func (*List) IteratorAsc

func (l *List) IteratorAsc(f func(e *Element) bool)

IteratorAsc iterates the list in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*List) IteratorDesc

func (l *List) IteratorDesc(f func(e *Element) bool)

IteratorDesc iterates the list in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*List) Len

func (l *List) Len() (length int)

Len returns the number of elements of list <l>. The complexity is O(1).

func (*List) LockFunc

func (l *List) LockFunc(f func(list *list.List))

LockFunc locks writing with given callback function <f> within RWMutex.Lock.

func (*List) MarshalJSON

func (l *List) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*List) MoveAfter

func (l *List) MoveAfter(e, p *Element)

MoveAfter moves element <e> to its new position after <p>. If <e> or <p> is not an element of <l>, or <e> == <p>, the list is not modified. The element and <p> must not be nil.

func (*List) MoveBefore

func (l *List) MoveBefore(e, p *Element)

MoveBefore moves element <e> to its new position before <p>. If <e> or <p> is not an element of <l>, or <e> == <p>, the list is not modified. The element and <p> must not be nil.

func (*List) MoveToBack

func (l *List) MoveToBack(e *Element)

MoveToBack moves element <e> to the back of list <l>. If <e> is not an element of <l>, the list is not modified. The element must not be nil.

func (*List) MoveToFront

func (l *List) MoveToFront(e *Element)

MoveToFront moves element <e> to the front of list <l>. If <e> is not an element of <l>, the list is not modified. The element must not be nil.

func (*List) PopBack

func (l *List) PopBack() (value interface{})

PopBack removes the element from back of <l> and returns the value of the element.

func (*List) PopBackAll

func (l *List) PopBackAll() []interface{}

PopBackAll removes all elements from back of <l> and returns values of the removed elements as slice.

func (*List) PopBacks

func (l *List) PopBacks(max int) (values []interface{})

PopBacks removes <max> elements from back of <l> and returns values of the removed elements as slice.

func (*List) PopFront

func (l *List) PopFront() (value interface{})

PopFront removes the element from front of <l> and returns the value of the element.

func (*List) PopFrontAll

func (l *List) PopFrontAll() []interface{}

PopFrontAll removes all elements from front of <l> and returns values of the removed elements as slice.

func (*List) PopFronts

func (l *List) PopFronts(max int) (values []interface{})

PopFronts removes <max> elements from front of <l> and returns values of the removed elements as slice.

func (*List) PushBack

func (l *List) PushBack(v interface{}) (e *Element)

PushBack inserts a new element <e> with value <v> at the back of list <l> and returns <e>.

func (*List) PushBackList

func (l *List) PushBackList(other *List)

PushBackList inserts a copy of an other list at the back of list <l>. The lists <l> and <other> may be the same, but they must not be nil.

func (*List) PushBacks

func (l *List) PushBacks(values []interface{})

PushBacks inserts multiple new elements with values <values> at the back of list <l>.

func (*List) PushFront

func (l *List) PushFront(v interface{}) (e *Element)

PushFront inserts a new element <e> with value <v> at the front of list <l> and returns <e>.

func (*List) PushFrontList

func (l *List) PushFrontList(other *List)

PushFrontList inserts a copy of an other list at the front of list <l>. The lists <l> and <other> may be the same, but they must not be nil.

func (*List) PushFronts

func (l *List) PushFronts(values []interface{})

PushFronts inserts multiple new elements with values <values> at the front of list <l>.

func (*List) RLockFunc

func (l *List) RLockFunc(f func(list *list.List))

RLockFunc locks reading with given callback function <f> within RWMutex.RLock.

func (*List) Remove

func (l *List) Remove(e *Element) (value interface{})

Remove removes <e> from <l> if <e> is an element of list <l>. It returns the element value e.Value. The element must not be nil.

func (*List) RemoveAll

func (l *List) RemoveAll()

RemoveAll removes all elements from list <l>.

func (*List) Removes

func (l *List) Removes(es []*Element)

Removes removes multiple elements <es> from <l> if <es> are elements of list <l>.

func (*List) Size

func (l *List) Size() int

Size is alias of Len.

func (*List) UnmarshalJSON

func (l *List) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type Pool

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

Goroutine Pool

func NewPool

func NewPool(limit ...int) *Pool

New creates and returns a new goroutine pool object. The parameter <limit> is used to limit the max goroutine count, which is not limited in default.

func (*Pool) Add

func (p *Pool) Add(f func()) error

Add pushes a new job to the pool. The job will be executed asynchronously.

func (*Pool) Cap

func (p *Pool) Cap() int

Cap returns the capacity of the pool. This capacity is defined when pool is created. If it returns -1 means no limit.

func (*Pool) Close

func (p *Pool) Close()

Close closes the goroutine pool, which makes all goroutines exit.

func (*Pool) IsClosed

func (p *Pool) IsClosed() bool

IsClosed returns if pool is closed.

func (*Pool) Jobs

func (p *Pool) Jobs() int

Jobs returns current job count of the pool.

func (*Pool) Size

func (p *Pool) Size() int

Size returns current goroutine count of the pool.

type RWMutex

type RWMutex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RWMutex is a sync.RWMutex with a switch of concurrent safe feature.

func NewRWMutex

func NewRWMutex(safe ...bool) *RWMutex

New creates and returns a new *RWMutex. The parameter <safe> is used to specify whether using this mutex in concurrent-safety, which is false in default.

func (*RWMutex) IsSafe

func (mu *RWMutex) IsSafe() bool

func (*RWMutex) Lock

func (mu *RWMutex) Lock()

func (*RWMutex) RLock

func (mu *RWMutex) RLock()

func (*RWMutex) RUnlock

func (mu *RWMutex) RUnlock()

func (*RWMutex) Unlock

func (mu *RWMutex) Unlock()

Jump to

Keyboard shortcuts

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