Skip to content

Commit

Permalink
deal with removal of forEachG linkname availability
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kortschak committed May 23, 2024
1 parent 82b69a0 commit d3b1e56
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
32 changes: 32 additions & 0 deletions gid_family_g121.go
Original file line number Diff line number Diff line change
@@ -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))
20 changes: 0 additions & 20 deletions gid_g121.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,10 @@

package goroutine

import "unsafe"

// ParentID returns the runtime ID of goroutine that created the calling
// goroutine.
func ParentID() int64 {
return idOf(getg(), parentGoidoff)
}

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))

0 comments on commit d3b1e56

Please sign in to comment.