github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zsync/utils.go (about) 1 package zsync 2 3 import ( 4 "runtime" 5 _ "unsafe" 6 ) 7 8 const ( 9 cacheLineSize = 64 10 ) 11 12 func nextPowOf2(v uint32) uint32 { 13 v-- 14 v |= v >> 1 15 v |= v >> 2 16 v |= v >> 4 17 v |= v >> 8 18 v |= v >> 16 19 v++ 20 return v 21 } 22 23 func parallelism() uint32 { 24 maxProcs := uint32(runtime.GOMAXPROCS(0)) 25 numCores := uint32(runtime.NumCPU()) 26 if maxProcs < numCores { 27 return maxProcs 28 } 29 return numCores 30 }