github.com/GoWebProd/gip@v0.0.0-20230623090727-b60d41d5d320/pool/chainElt.go (about)

     1  package pool
     2  
     3  import (
     4  	"sync/atomic"
     5  	"unsafe"
     6  )
     7  
     8  type poolChainElt[T any] struct {
     9  	poolDequeue[T]
    10  
    11  	// next and prev link to the adjacent poolChainElts in this
    12  	// poolChain.
    13  	//
    14  	// next is written atomically by the producer and read
    15  	// atomically by the consumer. It only transitions from nil to
    16  	// non-nil.
    17  	//
    18  	// prev is written atomically by the consumer and read
    19  	// atomically by the producer. It only transitions from
    20  	// non-nil to nil.
    21  	next, prev *poolChainElt[T]
    22  }
    23  
    24  func storePoolChainElt[T any](pp **poolChainElt[T], v *poolChainElt[T]) {
    25  	atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(pp)), unsafe.Pointer(v))
    26  }
    27  
    28  func loadPoolChainElt[T any](pp **poolChainElt[T]) *poolChainElt[T] {
    29  	return (*poolChainElt[T])(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(pp))))
    30  }