mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: trivial replacements of _g_ in os files
Change-Id: I7886ea6b94697bafb8ea345508c9cb752c92cadc Reviewed-on: https://go-review.googlesource.com/c/go/+/418586 Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
0e18cf6d09
commit
5999a28de8
4 changed files with 31 additions and 31 deletions
|
|
@ -388,11 +388,11 @@ func exit1(code int32)
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func exit(code int32) {
|
func exit(code int32) {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of g because without a g during
|
// Check the validity of g because without a g during
|
||||||
// newosproc0.
|
// newosproc0.
|
||||||
if _g_ != nil {
|
if gp != nil {
|
||||||
syscall1(&libc_exit, uintptr(code))
|
syscall1(&libc_exit, uintptr(code))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -403,11 +403,11 @@ func write2(fd, p uintptr, n int32) int32
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
|
func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of g because without a g during
|
// Check the validity of g because without a g during
|
||||||
// newosproc0.
|
// newosproc0.
|
||||||
if _g_ != nil {
|
if gp != nil {
|
||||||
r, errno := syscall3(&libc_write, uintptr(fd), uintptr(p), uintptr(n))
|
r, errno := syscall3(&libc_write, uintptr(fd), uintptr(p), uintptr(n))
|
||||||
if int32(r) < 0 {
|
if int32(r) < 0 {
|
||||||
return -int32(errno)
|
return -int32(errno)
|
||||||
|
|
@ -493,11 +493,11 @@ func sigaction1(sig, new, old uintptr)
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func sigaction(sig uintptr, new, old *sigactiont) {
|
func sigaction(sig uintptr, new, old *sigactiont) {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of g because without a g during
|
// Check the validity of g because without a g during
|
||||||
// runtime.libpreinit.
|
// runtime.libpreinit.
|
||||||
if _g_ != nil {
|
if gp != nil {
|
||||||
r, err := syscall3(&libc_sigaction, sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
|
r, err := syscall3(&libc_sigaction, sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
|
||||||
if int32(r) == -1 {
|
if int32(r) == -1 {
|
||||||
println("Sigaction failed for sig: ", sig, " with error:", hex(err))
|
println("Sigaction failed for sig: ", sig, " with error:", hex(err))
|
||||||
|
|
@ -645,11 +645,11 @@ func pthread_attr_init1(attr uintptr) int32
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func pthread_attr_init(attr *pthread_attr) int32 {
|
func pthread_attr_init(attr *pthread_attr) int32 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of g because without a g during
|
// Check the validity of g because without a g during
|
||||||
// newosproc0.
|
// newosproc0.
|
||||||
if _g_ != nil {
|
if gp != nil {
|
||||||
r, _ := syscall1(&libpthread_attr_init, uintptr(unsafe.Pointer(attr)))
|
r, _ := syscall1(&libpthread_attr_init, uintptr(unsafe.Pointer(attr)))
|
||||||
return int32(r)
|
return int32(r)
|
||||||
}
|
}
|
||||||
|
|
@ -661,11 +661,11 @@ func pthread_attr_setdetachstate1(attr uintptr, state int32) int32
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func pthread_attr_setdetachstate(attr *pthread_attr, state int32) int32 {
|
func pthread_attr_setdetachstate(attr *pthread_attr, state int32) int32 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of g because without a g during
|
// Check the validity of g because without a g during
|
||||||
// newosproc0.
|
// newosproc0.
|
||||||
if _g_ != nil {
|
if gp != nil {
|
||||||
r, _ := syscall2(&libpthread_attr_setdetachstate, uintptr(unsafe.Pointer(attr)), uintptr(state))
|
r, _ := syscall2(&libpthread_attr_setdetachstate, uintptr(unsafe.Pointer(attr)), uintptr(state))
|
||||||
return int32(r)
|
return int32(r)
|
||||||
}
|
}
|
||||||
|
|
@ -689,11 +689,11 @@ func pthread_attr_setstacksize1(attr uintptr, size uint64) int32
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func pthread_attr_setstacksize(attr *pthread_attr, size uint64) int32 {
|
func pthread_attr_setstacksize(attr *pthread_attr, size uint64) int32 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of g because without a g during
|
// Check the validity of g because without a g during
|
||||||
// newosproc0.
|
// newosproc0.
|
||||||
if _g_ != nil {
|
if gp != nil {
|
||||||
r, _ := syscall2(&libpthread_attr_setstacksize, uintptr(unsafe.Pointer(attr)), uintptr(size))
|
r, _ := syscall2(&libpthread_attr_setstacksize, uintptr(unsafe.Pointer(attr)), uintptr(size))
|
||||||
return int32(r)
|
return int32(r)
|
||||||
}
|
}
|
||||||
|
|
@ -705,11 +705,11 @@ func pthread_create1(tid, attr, fn, arg uintptr) int32
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func pthread_create(tid *pthread, attr *pthread_attr, fn *funcDescriptor, arg unsafe.Pointer) int32 {
|
func pthread_create(tid *pthread, attr *pthread_attr, fn *funcDescriptor, arg unsafe.Pointer) int32 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of g because without a g during
|
// Check the validity of g because without a g during
|
||||||
// newosproc0.
|
// newosproc0.
|
||||||
if _g_ != nil {
|
if gp != nil {
|
||||||
r, _ := syscall4(&libpthread_create, uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
|
r, _ := syscall4(&libpthread_create, uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
|
||||||
return int32(r)
|
return int32(r)
|
||||||
}
|
}
|
||||||
|
|
@ -723,11 +723,11 @@ func sigprocmask1(how, new, old uintptr)
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func sigprocmask(how int32, new, old *sigset) {
|
func sigprocmask(how int32, new, old *sigset) {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Check the validity of m because it might be called during a cgo
|
// Check the validity of m because it might be called during a cgo
|
||||||
// callback early enough where m isn't available yet.
|
// callback early enough where m isn't available yet.
|
||||||
if _g_ != nil && _g_.m != nil {
|
if gp != nil && gp.m != nil {
|
||||||
r, err := syscall3(&libpthread_sigthreadmask, uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
|
r, err := syscall3(&libpthread_sigthreadmask, uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
|
||||||
if int32(r) != 0 {
|
if int32(r) != 0 {
|
||||||
println("syscall sigthreadmask failed: ", hex(err))
|
println("syscall sigthreadmask failed: ", hex(err))
|
||||||
|
|
|
||||||
|
|
@ -152,16 +152,16 @@ func semacreate(mp *m) {
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func semasleep(ns int64) int32 {
|
func semasleep(ns int64) int32 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
var deadline int64
|
var deadline int64
|
||||||
if ns >= 0 {
|
if ns >= 0 {
|
||||||
deadline = nanotime() + ns
|
deadline = nanotime() + ns
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
v := atomic.Load(&_g_.m.waitsemacount)
|
v := atomic.Load(&gp.m.waitsemacount)
|
||||||
if v > 0 {
|
if v > 0 {
|
||||||
if atomic.Cas(&_g_.m.waitsemacount, v, v-1) {
|
if atomic.Cas(&gp.m.waitsemacount, v, v-1) {
|
||||||
return 0 // semaphore acquired
|
return 0 // semaphore acquired
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|
@ -178,7 +178,7 @@ func semasleep(ns int64) int32 {
|
||||||
ts.setNsec(wait)
|
ts.setNsec(wait)
|
||||||
tsp = &ts
|
tsp = &ts
|
||||||
}
|
}
|
||||||
ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil)
|
ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&gp.m.waitsemacount), nil)
|
||||||
if ret == _ETIMEDOUT {
|
if ret == _ETIMEDOUT {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
@ -289,8 +289,8 @@ func mpreinit(mp *m) {
|
||||||
// Called to initialize a new m (including the bootstrap m).
|
// Called to initialize a new m (including the bootstrap m).
|
||||||
// Called on the new thread, cannot allocate memory.
|
// Called on the new thread, cannot allocate memory.
|
||||||
func minit() {
|
func minit() {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
_g_.m.procid = uint64(lwp_self())
|
gp.m.procid = uint64(lwp_self())
|
||||||
|
|
||||||
// On NetBSD a thread created by pthread_create inherits the
|
// On NetBSD a thread created by pthread_create inherits the
|
||||||
// signal stack of the creating thread. We always create a
|
// signal stack of the creating thread. We always create a
|
||||||
|
|
@ -299,8 +299,8 @@ func minit() {
|
||||||
// created in C that calls sigaltstack and then calls a Go
|
// created in C that calls sigaltstack and then calls a Go
|
||||||
// function, because we will lose track of the C code's
|
// function, because we will lose track of the C code's
|
||||||
// sigaltstack, but it's the best we can do.
|
// sigaltstack, but it's the best we can do.
|
||||||
signalstack(&_g_.m.gsignal.stack)
|
signalstack(&gp.m.gsignal.stack)
|
||||||
_g_.m.newSigstack = true
|
gp.m.newSigstack = true
|
||||||
|
|
||||||
minitSignalMask()
|
minitSignalMask()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func semacreate(mp *m) {
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func semasleep(ns int64) int32 {
|
func semasleep(ns int64) int32 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
|
|
||||||
// Compute sleep deadline.
|
// Compute sleep deadline.
|
||||||
var tsp *timespec
|
var tsp *timespec
|
||||||
|
|
@ -95,9 +95,9 @@ func semasleep(ns int64) int32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
v := atomic.Load(&_g_.m.waitsemacount)
|
v := atomic.Load(&gp.m.waitsemacount)
|
||||||
if v > 0 {
|
if v > 0 {
|
||||||
if atomic.Cas(&_g_.m.waitsemacount, v, v-1) {
|
if atomic.Cas(&gp.m.waitsemacount, v, v-1) {
|
||||||
return 0 // semaphore acquired
|
return 0 // semaphore acquired
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|
@ -110,7 +110,7 @@ func semasleep(ns int64) int32 {
|
||||||
// be examined [...] immediately before blocking. If that int
|
// be examined [...] immediately before blocking. If that int
|
||||||
// is non-zero then __thrsleep() will immediately return EINTR
|
// is non-zero then __thrsleep() will immediately return EINTR
|
||||||
// without blocking."
|
// without blocking."
|
||||||
ret := thrsleep(uintptr(unsafe.Pointer(&_g_.m.waitsemacount)), _CLOCK_MONOTONIC, tsp, 0, &_g_.m.waitsemacount)
|
ret := thrsleep(uintptr(unsafe.Pointer(&gp.m.waitsemacount)), _CLOCK_MONOTONIC, tsp, 0, &gp.m.waitsemacount)
|
||||||
if ret == _EWOULDBLOCK {
|
if ret == _EWOULDBLOCK {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -473,19 +473,19 @@ func semacreate(mp *m) {
|
||||||
|
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func semasleep(ns int64) int {
|
func semasleep(ns int64) int {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
if ns >= 0 {
|
if ns >= 0 {
|
||||||
ms := timediv(ns, 1000000, nil)
|
ms := timediv(ns, 1000000, nil)
|
||||||
if ms == 0 {
|
if ms == 0 {
|
||||||
ms = 1
|
ms = 1
|
||||||
}
|
}
|
||||||
ret := plan9_tsemacquire(&_g_.m.waitsemacount, ms)
|
ret := plan9_tsemacquire(&gp.m.waitsemacount, ms)
|
||||||
if ret == 1 {
|
if ret == 1 {
|
||||||
return 0 // success
|
return 0 // success
|
||||||
}
|
}
|
||||||
return -1 // timeout or interrupted
|
return -1 // timeout or interrupted
|
||||||
}
|
}
|
||||||
for plan9_semacquire(&_g_.m.waitsemacount, 1) < 0 {
|
for plan9_semacquire(&gp.m.waitsemacount, 1) < 0 {
|
||||||
// interrupted; try again (c.f. lock_sema.go)
|
// interrupted; try again (c.f. lock_sema.go)
|
||||||
}
|
}
|
||||||
return 0 // success
|
return 0 // success
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue