Documentation ¶
Overview ¶
Package queue provides a lock-free queue and two-Lock concurrent queue which use the algorithm proposed by Michael and Scott. https://doi.org/10.1145/248052.248106.
see pseudocode at https://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html It will be refactored after go generic is released.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoundedQueue ¶
type BoundedQueue struct {
// contains filtered or unexported fields
}
BoundedQueue is a threadsafe bounded queue.
func NewBoundedQueue ¶
func NewBoundedQueue(n uint32) *BoundedQueue
NewBoundedQueue create a BoundedQueue.
func (*BoundedQueue) Dequeue ¶
func (q *BoundedQueue) Dequeue() interface{}
Dequeue removes and returns the value at the head of the queue. It will be blocked if the queue is empty.
func (*BoundedQueue) Enqueue ¶
func (q *BoundedQueue) Enqueue(v interface{})
Enqueue puts the given value v at the tail of the queue. If this queue if full, the caller will be blocked.
type CQueue ¶
type CQueue struct {
// contains filtered or unexported fields
}
CQueue is a concurrent unbounded queue which uses two-Lock concurrent queue qlgorithm.
type LKQueue ¶
type LKQueue struct {
// contains filtered or unexported fields
}
LKQueue is a lock-free unbounded queue.
func (*LKQueue) Dequeue ¶
func (q *LKQueue) Dequeue() interface{}
Dequeue removes and returns the value at the head of the queue. It returns nil if the queue is empty.
type Queue ¶
type Queue interface { Enqueue(v interface{}) Dequeue() interface{} }
Queue is a FIFO data structure. Enqueue puts a value into its tail, Dequeue removes a value from its head.
type SliceQueue ¶
type SliceQueue struct {
// contains filtered or unexported fields
}
SliceQueue is an unbounded queue which uses a slice as underlying.
func NewSliceQueue ¶
func NewSliceQueue(n int) (q *SliceQueue)
NewSliceQueue returns an empty queue.
func (*SliceQueue) Dequeue ¶
func (q *SliceQueue) Dequeue() interface{}
Dequeue removes and returns the value at the head of the queue. It returns nil if the queue is empty.
func (*SliceQueue) Enqueue ¶
func (q *SliceQueue) Enqueue(v interface{})
Enqueue puts the given value v at the tail of the queue.