1
0
mirror of https://github.com/golang/go synced 2024-11-26 20:11:26 -07:00

runtime: mark atomic methods which call nosplit functions as nosplit

Fixes #54411

Change-Id: I482ebca7365862bfb82a9daf8111c6f395aa1170
Reviewed-on: https://go-review.googlesource.com/c/go/+/423255
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cuong Manh Le 2022-08-12 16:38:56 +07:00
parent a2af095699
commit 57c1edcaec

View File

@ -100,6 +100,8 @@ type Uint8 struct {
} }
// Load accesses and returns the value atomically. // Load accesses and returns the value atomically.
//
//go:nosplit
func (u *Uint8) Load() uint8 { func (u *Uint8) Load() uint8 {
return Load8(&u.value) return Load8(&u.value)
} }
@ -136,6 +138,8 @@ type Bool struct {
} }
// Load accesses and returns the value atomically. // Load accesses and returns the value atomically.
//
//go:nosplit
func (b *Bool) Load() bool { func (b *Bool) Load() bool {
return b.u.Load() != 0 return b.u.Load() != 0
} }
@ -158,6 +162,8 @@ type Uint32 struct {
} }
// Load accesses and returns the value atomically. // Load accesses and returns the value atomically.
//
//go:nosplit
func (u *Uint32) Load() uint32 { func (u *Uint32) Load() uint32 {
return Load(&u.value) return Load(&u.value)
} }
@ -169,6 +175,8 @@ func (u *Uint32) Load() uint32 {
// on this thread can be observed to occur before it. // on this thread can be observed to occur before it.
// //
// WARNING: Use sparingly and with great care. // WARNING: Use sparingly and with great care.
//
//go:nosplit
func (u *Uint32) LoadAcquire() uint32 { func (u *Uint32) LoadAcquire() uint32 {
return LoadAcq(&u.value) return LoadAcq(&u.value)
} }
@ -255,6 +263,8 @@ type Uint64 struct {
} }
// Load accesses and returns the value atomically. // Load accesses and returns the value atomically.
//
//go:nosplit
func (u *Uint64) Load() uint64 { func (u *Uint64) Load() uint64 {
return Load64(&u.value) return Load64(&u.value)
} }
@ -283,6 +293,8 @@ func (u *Uint64) Swap(value uint64) uint64 {
// //
// This operation wraps around in the usual // This operation wraps around in the usual
// two's-complement way. // two's-complement way.
//
//go:nosplit
func (u *Uint64) Add(delta int64) uint64 { func (u *Uint64) Add(delta int64) uint64 {
return Xadd64(&u.value, delta) return Xadd64(&u.value, delta)
} }
@ -307,6 +319,8 @@ func (u *Uintptr) Load() uintptr {
// on this thread can be observed to occur before it. // on this thread can be observed to occur before it.
// //
// WARNING: Use sparingly and with great care. // WARNING: Use sparingly and with great care.
//
//go:nosplit
func (u *Uintptr) LoadAcquire() uintptr { func (u *Uintptr) LoadAcquire() uintptr {
return LoadAcquintptr(&u.value) return LoadAcquintptr(&u.value)
} }
@ -361,6 +375,8 @@ type Float64 struct {
} }
// Load accesses and returns the value atomically. // Load accesses and returns the value atomically.
//
//go:nosplit
func (f *Float64) Load() float64 { func (f *Float64) Load() float64 {
r := f.u.Load() r := f.u.Load()
return *(*float64)(unsafe.Pointer(&r)) return *(*float64)(unsafe.Pointer(&r))
@ -386,6 +402,8 @@ type UnsafePointer struct {
} }
// Load accesses and returns the value atomically. // Load accesses and returns the value atomically.
//
//go:nosplit
func (u *UnsafePointer) Load() unsafe.Pointer { func (u *UnsafePointer) Load() unsafe.Pointer {
return Loadp(unsafe.Pointer(&u.value)) return Loadp(unsafe.Pointer(&u.value))
} }
@ -420,6 +438,8 @@ type Pointer[T any] struct {
} }
// Load accesses and returns the value atomically. // Load accesses and returns the value atomically.
//
//go:nosplit
func (p *Pointer[T]) Load() *T { func (p *Pointer[T]) Load() *T {
return (*T)(p.u.Load()) return (*T)(p.u.Load())
} }