Skip to content

Commit 889a976

Browse files
authored
Merge pull request #6 from RaduBerinde/add-current-p
cockroach-go1.23.12: runtime: add CurrentP
2 parents 309f111 + 967a856 commit 889a976

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/runtime/cockroach.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package runtime
2+
3+
// CurrentP returns the index of the current P, between 0 and the current
4+
// GOMAXPROCS.
5+
//
6+
// This can only be used as a best-effort facility; there is no guarantee that
7+
// the goroutine still runs on the same P when this function returns.
8+
func CurrentP() int {
9+
// Note: preemption is not possible in-between these loads (there are no
10+
// preemption-safe points).
11+
return int(getg().m.p.ptr().id)
12+
}

0 commit comments

Comments
 (0)