From 8732da19a64853834ca155cafc1d7b2967290c31 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Wed, 27 Sep 2023 14:38:45 +0200 Subject: [PATCH] sync/atomic: document that atomic types should not be copied Change-Id: I07462692c1e26da3aad755b991d8026e66254534 --- src/sync/atomic/type.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sync/atomic/type.go b/src/sync/atomic/type.go index 179fa93092..f950bc0bed 100644 --- a/src/sync/atomic/type.go +++ b/src/sync/atomic/type.go @@ -8,6 +8,8 @@ import "unsafe" // A Bool is an atomic boolean value. // The zero value is false. +// +// Bool must not be copied after first use. type Bool struct { _ noCopy v uint32 @@ -40,6 +42,8 @@ func b32(b bool) uint32 { var _ = &Pointer[int]{} // A Pointer is an atomic pointer of type *T. The zero value is a nil *T. +// +// Pointer must not be copied after first use. type Pointer[T any] struct { // Mention *T in a field to disallow conversion between Pointer types. // See go.dev/issue/56603 for more details. @@ -65,6 +69,8 @@ func (x *Pointer[T]) CompareAndSwap(old, new *T) (swapped bool) { } // An Int32 is an atomic int32. The zero value is zero. +// +// Int32 must not be copied after first use. type Int32 struct { _ noCopy v int32 @@ -88,6 +94,8 @@ func (x *Int32) CompareAndSwap(old, new int32) (swapped bool) { func (x *Int32) Add(delta int32) (new int32) { return AddInt32(&x.v, delta) } // An Int64 is an atomic int64. The zero value is zero. +// +// Int64 must not be copied after first use. type Int64 struct { _ noCopy _ align64 @@ -112,6 +120,8 @@ func (x *Int64) CompareAndSwap(old, new int64) (swapped bool) { func (x *Int64) Add(delta int64) (new int64) { return AddInt64(&x.v, delta) } // A Uint32 is an atomic uint32. The zero value is zero. +// +// Uint32 must not be copied after first use. type Uint32 struct { _ noCopy v uint32 @@ -135,6 +145,8 @@ func (x *Uint32) CompareAndSwap(old, new uint32) (swapped bool) { func (x *Uint32) Add(delta uint32) (new uint32) { return AddUint32(&x.v, delta) } // A Uint64 is an atomic uint64. The zero value is zero. +// +// Uint64 must not be copied after first use. type Uint64 struct { _ noCopy _ align64 @@ -159,6 +171,8 @@ func (x *Uint64) CompareAndSwap(old, new uint64) (swapped bool) { func (x *Uint64) Add(delta uint64) (new uint64) { return AddUint64(&x.v, delta) } // A Uintptr is an atomic uintptr. The zero value is zero. +// +// Uintptr must not be copied after first use. type Uintptr struct { _ noCopy v uintptr