github.com/andy2046/gopie@v0.7.0/pkg/spsc/util.go (about)

     1  package spsc
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  type iface struct {
     8  	t, d unsafe.Pointer
     9  }
    10  
    11  func extractptr(i interface{}) unsafe.Pointer {
    12  	return (*iface)(unsafe.Pointer(&i)).d
    13  }
    14  
    15  func inject(i interface{}, ptr unsafe.Pointer) {
    16  	var v = (*unsafe.Pointer)((*iface)(unsafe.Pointer(&i)).d)
    17  	*v = ptr
    18  }
    19  
    20  func nextPowerOf2(v uint32) uint32 {
    21  	v--
    22  	v |= v >> 1
    23  	v |= v >> 2
    24  	v |= v >> 4
    25  	v |= v >> 8
    26  	v |= v >> 16
    27  	return v + 1
    28  }