github.com/GoWebProd/gip@v0.0.0-20230623090727-b60d41d5d320/pool/local.go (about) 1 package pool 2 3 import "unsafe" 4 5 // Local per-P Pool appendix. 6 type poolLocalInternal[T any] struct { 7 private *T // Can be used only by the respective P. 8 shared poolChain[T] // Local P can pushHead/popHead; any P can popTail. 9 } 10 11 type poolLocal[T any] struct { 12 poolLocalInternal[T] 13 14 // Prevents false sharing on widespread platforms with 15 // 128 mod (cache line size) = 0 . 16 pad [128 - unsafe.Sizeof(poolLocalInternal[T]{})%128]byte 17 } 18 19 func indexLocal[T any](l unsafe.Pointer, i int) *poolLocal[T] { 20 lp := unsafe.Pointer(uintptr(l) + uintptr(i)*unsafe.Sizeof(poolLocal[T]{})) 21 return (*poolLocal[T])(lp) 22 }