Пример #1
0
// New returns a new Queue, with size rounded up to the next power of 2.
func New(size uint) *Queue {
	size2 := primitive.Next2(uintptr(size))
	cells := make([]cell, size2+1) // pad one cell at the start to avoid sharing it
	for i := uintptr(0); i < size2+1; i++ {
		cells[i].seq = i - 1 // remove the pad cell from the sequence number
	}

	q := &Queue{
		mask:  size2 - 1,
		cells: cells[1:],
	}
	return q
}
Пример #2
0
// New returns a new Queue, with size rounded up to the next power of 2.
func New(size uint) *Queue {
	size2 := primitive.Next2(uintptr(size))
	cells := make([]cell, size2+1)
	for i := uintptr(0); i < size2+1; i++ {
		cells[i].seq = i - 1
	}

	q := &Queue{
		mask:  size2 - 1,
		cells: cells[1:],
	}
	return q
}