Added more comments

This commit is contained in:
Kevin Krakauer
2021-05-06 13:04:59 -07:00
parent 413f1d654f
commit a6c623ed9f
+6
View File
@@ -35,6 +35,9 @@ type AlignedAtomicInt64 struct {
}
func (aa *AlignedAtomicInt64) ptr() *int64 {
// In the 15-byte aa.value, there are guaranteed to be 8 contiguous
// bytes with 64-bit alignment. We find an address in this range by
// adding 7, then clear the 3 least significant bits to get its start.
return (*int64)(unsafe.Pointer((uintptr(unsafe.Pointer(&aa.value)) + 7) &^ 7))
}
@@ -67,6 +70,9 @@ type AlignedAtomicUint64 struct {
}
func (aa *AlignedAtomicUint64) ptr() *uint64 {
// In the 15-byte aa.value, there are guaranteed to be 8 contiguous
// bytes with 64-bit alignment. We find an address in this range by
// adding 7, then clear the 3 least significant bits to get its start.
return (*uint64)(unsafe.Pointer((uintptr(unsafe.Pointer(&aa.value)) + 7) &^ 7))
}