summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2021-03-30 15:03:08 -0700
committerKevin Krakauer <krakauer@google.com>2021-05-06 13:04:59 -0700
commita6c623ed9f971d6fbebddaf9ad03d357994647cc (patch)
tree33c84034e6503ac0fb3462de96c102357462b271
parent413f1d654f2b0fb8c43fe9e22d8083789abdf856 (diff)
Added more comments
-rw-r--r--pkg/atomicbitops/aligned_32bit_unsafe.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/pkg/atomicbitops/aligned_32bit_unsafe.go b/pkg/atomicbitops/aligned_32bit_unsafe.go
index a5c762f67..200fc0092 100644
--- a/pkg/atomicbitops/aligned_32bit_unsafe.go
+++ b/pkg/atomicbitops/aligned_32bit_unsafe.go
@@ -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))
}