mirror of https://github.com/golang/go.git
sync/atomic: document that atomic types should not be copied
Change-Id: I07462692c1e26da3aad755b991d8026e66254534
This commit is contained in:
parent
5152be3959
commit
8732da19a6
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue