sync

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 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 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

stack资料结构,容量固定 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