tendermint: github.com/tendermint/tendermint/libs/clist Index | Files

package clist

import "github.com/tendermint/tendermint/libs/clist"

Index

Package Files

clist.go

Constants

const MaxLength = int(^uint(0) >> 1)

MaxLength is the max allowed number of elements a linked list is allowed to contain. If more elements are pushed to the list it will panic.

type CElement Uses

type CElement struct {
    Value interface{} // immutable
    // contains filtered or unexported fields
}

CElement is an element of a linked-list Traversal from a CElement is goroutine-safe.

We can't avoid using WaitGroups or for-loops given the documentation spec without re-implementing the primitives that already exist in golang/sync. Notice that WaitGroup allows many go-routines to be simultaneously released, which is what we want. Mutex doesn't do this. RWMutex does this, but it's clumsy to use in the way that a WaitGroup would be used -- and we'd end up having two RWMutex's for prev/next each, which is doubly confusing.

sync.Cond would be sort-of useful, but we don't need a write-lock in the for-loop. Use sync.Cond when you need serial access to the "condition". In our case our condition is if `next != nil || removed`, and there's no reason to serialize that condition for goroutines waiting on NextWait() (since it's just a read operation).

func (*CElement) DetachNext Uses

func (e *CElement) DetachNext()

func (*CElement) DetachPrev Uses

func (e *CElement) DetachPrev()

func (*CElement) Next Uses

func (e *CElement) Next() *CElement

Nonblocking, may return nil if at the end.

func (*CElement) NextWait Uses

func (e *CElement) NextWait() *CElement

Blocking implementation of Next(). May return nil iff CElement was tail and got removed.

func (*CElement) NextWaitChan Uses

func (e *CElement) NextWaitChan() <-chan struct{}

NextWaitChan can be used to wait until Next becomes not nil. Once it does, channel will be closed.

func (*CElement) Prev Uses

func (e *CElement) Prev() *CElement

Nonblocking, may return nil if at the end.

func (*CElement) PrevWait Uses

func (e *CElement) PrevWait() *CElement

Blocking implementation of Prev(). May return nil iff CElement was head and got removed.

func (*CElement) PrevWaitChan Uses

func (e *CElement) PrevWaitChan() <-chan struct{}

PrevWaitChan can be used to wait until Prev becomes not nil. Once it does, channel will be closed.

func (*CElement) Removed Uses

func (e *CElement) Removed() bool

func (*CElement) SetNext Uses

func (e *CElement) SetNext(newNext *CElement)

NOTE: This function needs to be safe for concurrent goroutines waiting on nextWg.

func (*CElement) SetPrev Uses

func (e *CElement) SetPrev(newPrev *CElement)

NOTE: This function needs to be safe for concurrent goroutines waiting on prevWg

func (*CElement) SetRemoved Uses

func (e *CElement) SetRemoved()

type CList Uses

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

CList represents a linked list. The zero value for CList is an empty list ready to use. Operations are goroutine-safe. Panics if length grows beyond the max.

func New Uses

func New() *CList

Return CList with MaxLength. CList will panic if it goes beyond MaxLength.

func (*CList) Back Uses

func (l *CList) Back() *CElement

func (*CList) BackWait Uses

func (l *CList) BackWait() *CElement

func (*CList) Front Uses

func (l *CList) Front() *CElement

func (*CList) FrontWait Uses

func (l *CList) FrontWait() *CElement

func (*CList) Init Uses

func (l *CList) Init() *CList

func (*CList) Len Uses

func (l *CList) Len() int

func (*CList) PushBack Uses

func (l *CList) PushBack(v interface{}) *CElement

Panics if list grows beyond its max length.

func (*CList) Remove Uses

func (l *CList) Remove(e *CElement) interface{}

CONTRACT: Caller must call e.DetachPrev() and/or e.DetachNext() to avoid memory leaks. NOTE: As per the contract of CList, removed elements cannot be added back.

func (*CList) WaitChan Uses

func (l *CList) WaitChan() <-chan struct{}

WaitChan can be used to wait until Front or Back becomes not nil. Once it does, channel will be closed.

Package clist imports 2 packages (graph) and is imported by 7 packages. Updated 2019-06-30. Refresh now. Tools for package owners.