From d3b1e5692a2963f8cbf9c4aaa2834ca1b48bb5e9 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 23 May 2024 20:09:41 +0930 Subject: [PATCH] deal with removal of forEachG linkname availability This is arguably a breaking change, but not removing this prevents the package from building at all on go1.23, so given the universe we are in this is being treated as a bugfix. --- .github/workflows/go.yml | 5 +---- gid_family_g121.go | 32 ++++++++++++++++++++++++++++++++ gid_g121.go | 20 -------------------- 3 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 gid_family_g121.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index daf7346..a441f88 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,14 +12,13 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] go-version: - - 1.14.x - - 1.15.x - 1.16.x - 1.17.x - 1.18.x - 1.19.x - 1.20.x - 1.21.x + - 1.22.x runs-on: ${{ matrix.os }} steps: @@ -39,8 +38,6 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] go-version: - - 1.14.x - - 1.15.x - 1.16.x - 1.17.x - 1.18.x diff --git a/gid_family_g121.go b/gid_family_g121.go new file mode 100644 index 0000000..074747a --- /dev/null +++ b/gid_family_g121.go @@ -0,0 +1,32 @@ +// Copyright ©2023 Dan Kortschak. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build go1.21 && !go1.23 +// +build go1.21,!go1.23 + +package goroutine + +import "unsafe" + +// Link is a goroutine parent-child relationship. +// +// Only available for go1.21 and go1.22. +type Link struct { + Parent, Child int64 +} + +// All returns all the known goroutine parent-child relationships. +// +// Only available for go1.21 and go1.22. +func All() []Link { + var s []Link + forEachG(func(g unsafe.Pointer) { + s = append(s, Link{Parent: idOf(g, parentGoidoff), Child: idOf(g, goidoff)}) + }) + return s +} + +//go:linkname forEachG runtime.forEachG +//go:nosplit +func forEachG(fn func(gp unsafe.Pointer)) diff --git a/gid_g121.go b/gid_g121.go index 899f888..a80dda6 100644 --- a/gid_g121.go +++ b/gid_g121.go @@ -7,8 +7,6 @@ package goroutine -import "unsafe" - // ParentID returns the runtime ID of goroutine that created the calling // goroutine. func ParentID() int64 { @@ -16,21 +14,3 @@ func ParentID() int64 { } var parentGoidoff = offset("*runtime.g", "parentGoid") - -// Link is a goroutine parent-child relationship. -type Link struct { - Parent, Child int64 -} - -// All returns all the known goroutine parent-child relationships. -func All() []Link { - var s []Link - forEachG(func(g unsafe.Pointer) { - s = append(s, Link{Parent: idOf(g, parentGoidoff), Child: idOf(g, goidoff)}) - }) - return s -} - -//go:linkname forEachG runtime.forEachG -//go:nosplit -func forEachG(fn func(gp unsafe.Pointer))