aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikhil Benesch <nikhil.benesch@gmail.com>2020-10-13 07:17:55 +0000
committerIan Lance Taylor <iant@golang.org>2020-10-14 13:56:01 -0700
commitca56d576241c6783eb36eea526b42c4f3fbf697b (patch)
tree4c2d5a0f1dc34d4a445583b7ba349b51b2ee875e
parent61a43de58cb6de7212a622060500ad0a0fd94fae (diff)
downloadgcc-ca56d576241c6783eb36eea526b42c4f3fbf697b.zip
gcc-ca56d576241c6783eb36eea526b42c4f3fbf697b.tar.gz
gcc-ca56d576241c6783eb36eea526b42c4f3fbf697b.tar.bz2
runtime: correct semaphore implementation on netbsd
NetBSD's semaphores use the underlying lighweight process mechanism (LWP) on NetBSD, rather than pthreads. This means the m.prodcid needs to be set to the LWP ID rather than the pthread ID in order for unpark notifications to get sent to the right place. Introduce a new getProcID() method that selects the correct ID for the platform. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/261742
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--libgo/go/runtime/os_aix.go4
-rw-r--r--libgo/go/runtime/os_gccgo.go3
-rw-r--r--libgo/go/runtime/os_hurd.go4
-rw-r--r--libgo/go/runtime/os_linux.go4
-rw-r--r--libgo/go/runtime/os_netbsd.go17
-rw-r--r--libgo/go/runtime/os_solaris.go4
7 files changed, 30 insertions, 8 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 2c7a9bd..c37df37 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6cb7b9e924d84125f21f4a2a96aa0d59466056fe
+c5505c4e626fa4217911443b4db8b065855a0206
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/libgo/go/runtime/os_aix.go b/libgo/go/runtime/os_aix.go
index 951aeb6..f49b83c 100644
--- a/libgo/go/runtime/os_aix.go
+++ b/libgo/go/runtime/os_aix.go
@@ -21,6 +21,10 @@ type mOS struct {
waitsema uintptr // semaphore for parking on locks
}
+func getProcID() uint64 {
+ return uint64(gettid())
+}
+
//extern malloc
func libc_malloc(uintptr) unsafe.Pointer
diff --git a/libgo/go/runtime/os_gccgo.go b/libgo/go/runtime/os_gccgo.go
index ab19022..a8859c0 100644
--- a/libgo/go/runtime/os_gccgo.go
+++ b/libgo/go/runtime/os_gccgo.go
@@ -27,8 +27,7 @@ func mpreinit(mp *m) {
func minit() {
minitSignals()
- // FIXME: only works on linux for now.
- getg().m.procid = uint64(gettid())
+ getg().m.procid = getProcID()
}
// Called from dropm to undo the effect of an minit.
diff --git a/libgo/go/runtime/os_hurd.go b/libgo/go/runtime/os_hurd.go
index b3c6f80..1613b41 100644
--- a/libgo/go/runtime/os_hurd.go
+++ b/libgo/go/runtime/os_hurd.go
@@ -18,6 +18,10 @@ type mOS struct {
waitsema uintptr // semaphore for parking on locks
}
+func getProcID() uint64 {
+ return uint64(gettid())
+}
+
//extern malloc
func libc_malloc(uintptr) unsafe.Pointer
diff --git a/libgo/go/runtime/os_linux.go b/libgo/go/runtime/os_linux.go
index 5d55064..627b6d6 100644
--- a/libgo/go/runtime/os_linux.go
+++ b/libgo/go/runtime/os_linux.go
@@ -13,6 +13,10 @@ type mOS struct {
unused byte
}
+func getProcID() uint64 {
+ return uint64(gettid())
+}
+
func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32 {
return int32(syscall(_SYS_futex, uintptr(addr), uintptr(op), uintptr(val), uintptr(ts), uintptr(addr2), uintptr(val3)))
}
diff --git a/libgo/go/runtime/os_netbsd.go b/libgo/go/runtime/os_netbsd.go
index 69d2c71..89a8d07 100644
--- a/libgo/go/runtime/os_netbsd.go
+++ b/libgo/go/runtime/os_netbsd.go
@@ -14,12 +14,19 @@ type mOS struct {
waitsemacount uint32
}
+func getProcID() uint64 {
+ return uint64(lwp_self())
+}
+
+//extern _lwp_self
+func lwp_self() int32
+
//go:noescape
-//extern lwp_park
+//extern _lwp_park
func lwp_park(ts int32, rel int32, abstime *timespec, unpark int32, hint, unparkhint unsafe.Pointer) int32
//go:noescape
-//extern lwp_unpark
+//extern _lwp_unpark
func lwp_unpark(lwp int32, hint unsafe.Pointer) int32
//go:noescape
@@ -88,7 +95,7 @@ func semasleep(ns int64) int32 {
tsp = &ts
}
ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil)
- if ret == _ETIMEDOUT {
+ if ret != 0 && errno() == _ETIMEDOUT {
return -1
}
}
@@ -101,10 +108,10 @@ func semawakeup(mp *m) {
// "If the target LWP is not currently waiting, it will return
// immediately upon the next call to _lwp_park()."
ret := lwp_unpark(int32(mp.procid), unsafe.Pointer(&mp.waitsemacount))
- if ret != 0 && ret != _ESRCH {
+ if ret != 0 && errno() != _ESRCH {
// semawakeup can be called on signal stack.
systemstack(func() {
- print("thrwakeup addr=", &mp.waitsemacount, " sem=", mp.waitsemacount, " ret=", ret, "\n")
+ print("thrwakeup addr=", &mp.waitsemacount, " sem=", mp.waitsemacount, " errno=", errno(), "\n")
})
}
}
diff --git a/libgo/go/runtime/os_solaris.go b/libgo/go/runtime/os_solaris.go
index 63b5cd7..c568629 100644
--- a/libgo/go/runtime/os_solaris.go
+++ b/libgo/go/runtime/os_solaris.go
@@ -10,6 +10,10 @@ type mOS struct {
waitsema uintptr // semaphore for parking on locks
}
+func getProcID() uint64 {
+ return uint64(gettid())
+}
+
//extern malloc
func libc_malloc(uintptr) unsafe.Pointer