sync

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PoolChain added in v1.2.0

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

poolChain is a dynamically-sized version of poolDequeue.

This is implemented as a doubly-linked list queue of poolDequeues where each dequeue is double the size of the previous one. Once a dequeue fills up, this allocates a new one and only ever pushes to the latest dequeue. Pops happen from the other end of the list and once a dequeue is exhausted, it gets removed from the list.

func NewPoolChain added in v1.2.0

func NewPoolChain() *PoolChain

func (*PoolChain) PopHead added in v1.2.0

func (c *PoolChain) PopHead() (any, bool)

如果不断PopHead,当head指向的dequeue已经没元素时,head的参考指标也不会改变,也不会销毁当前的dequeue 也就是 dequeue的容量只会越开越大

func (*PoolChain) PopTail added in v1.2.0

func (c *PoolChain) PopTail() (any, bool)

func (*PoolChain) PushHead added in v1.2.0

func (c *PoolChain) PushHead(val any)

type PoolChainElt added in v1.2.0

type PoolChainElt struct {
	PoolDequeue
	// contains filtered or unexported fields
}

把双向链结构,元素放dequeue,每个节点都是一个dequeues(PoolDequeue)

type PoolDequeue

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

PoolDequeue is a lock-free fixed-size single-producer, multi-consumer queue. The single producer can both push and pop from the head, and consumers can pop from the tail.

It has the added feature that it nils out unused slots to avoid unnecessary retention of objects. This is important for sync.Pool, but not typically a property considered in the literature.

func (*PoolDequeue) PopHead

func (d *PoolDequeue) PopHead() (any, bool)

popHead removes and returns the element at the head of the queue. It returns false if the queue is empty. It must only be called by a single producer.

func (*PoolDequeue) PopTail

func (d *PoolDequeue) PopTail() (any, bool)

popTail removes and returns the element at the tail of the queue. It returns false if the queue is empty. It may be called by any number of consumers.

func (*PoolDequeue) PushHead

func (d *PoolDequeue) PushHead(val any) bool

pushHead adds val at the head of the queue. It returns false if the queue is full. It must only be called by a single producer.

type PoolDequeueI

type PoolDequeueI interface {
	PushHead(val any) bool
	PopHead() (any, bool)
	PopTail() (any, bool)
}

func NewPoolDequeue

func NewPoolDequeue(initSize int) PoolDequeueI

ring buffer资料结构,容量固定 push一律推到head pop可以head或是tail 可作FIFO也可LIFO

Jump to

Keyboard shortcuts

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