mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-06-24 11:07:16 +03:00
This should reduce the waste of memory on the padding from 128 bytes to 64 bytes on GOARCH=amd64, while preserving bigger padding for platforms with bigger cache line sizes. See https://stackoverflow.com/questions/68320687/why-are-most-cache-line-sizes-designed-to-be-64-byte-instead-of-32-128byte-now Thanks to @tIGO for the hint
18 lines
449 B
Go
18 lines
449 B
Go
package atomicutil
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"unsafe"
|
|
)
|
|
|
|
// Uint64 is like atomic.Uint64, but is protected from false sharing.
|
|
type Uint64 struct {
|
|
// The padding prevents false sharing with the previous memory location
|
|
_ [CacheLineSize - unsafe.Sizeof(atomic.Uint64{})%CacheLineSize]byte
|
|
|
|
atomic.Uint64
|
|
|
|
// The padding prevents false sharing with the next memory location
|
|
_ [CacheLineSize - unsafe.Sizeof(atomic.Uint64{})%CacheLineSize]byte
|
|
}
|