Source File
poolqueue.go
Belonging Package
sync
package sync
import (
)
const dequeueLimit = (1 << dequeueBits) / 4
type dequeueNil *struct{}
func ( *poolDequeue) ( uint64) (, uint32) {
const = 1<<dequeueBits - 1
= uint32(( >> dequeueBits) & )
= uint32( & )
return
}
func ( *poolDequeue) (, uint32) uint64 {
const = 1<<dequeueBits - 1
return (uint64() << dequeueBits) |
uint64(&)
}
func ( *poolDequeue) ( interface{}) bool {
:= atomic.LoadUint64(&.headTail)
, := .unpack()
:= atomic.LoadPointer(&.typ)
return false
}
if == nil {
= dequeueNil(nil)
}
*(*interface{})(unsafe.Pointer()) =
atomic.AddUint64(&.headTail, 1<<dequeueBits)
return true
}
func ( *poolDequeue) () (interface{}, bool) {
var *eface
for {
:= atomic.LoadUint64(&.headTail)
, := .unpack()
--
:= .pack(, )
func ( *poolDequeue) () (interface{}, bool) {
var *eface
for {
:= atomic.LoadUint64(&.headTail)
, := .unpack()
:= .pack(, +1)
:= *(*interface{})(unsafe.Pointer())
if == dequeueNil(nil) {
= nil
}
return , true
}
tail *poolChainElt
}
type poolChainElt struct {
poolDequeue
next, prev *poolChainElt
}
func ( **poolChainElt, *poolChainElt) {
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer()), unsafe.Pointer())
}
func ( **poolChainElt) *poolChainElt {
return (*poolChainElt)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer())))
}
func ( *poolChain) ( interface{}) {
:= .head
const = 8 // Must be a power of 2
= new(poolChainElt)
.vals = make([]eface, )
.head =
storePoolChainElt(&.tail, )
}
if .pushHead() {
return
}
= dequeueLimit
}
:= &poolChainElt{prev: }
.vals = make([]eface, )
.head =
storePoolChainElt(&.next, )
.pushHead()
}
func ( *poolChain) () (interface{}, bool) {
:= .head
for != nil {
if , := .popHead(); {
return ,
:= loadPoolChainElt(&.next)
if , := .popTail(); {
return ,
}
storePoolChainElt(&.prev, nil)
}
=
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |