diff --git a/src/runtime/cockroach.go b/src/runtime/cockroach.go new file mode 100644 index 00000000000000..5ff4399db75c33 --- /dev/null +++ b/src/runtime/cockroach.go @@ -0,0 +1,12 @@ +package runtime + +// CurrentP returns the index of the current P, between 0 and the current +// GOMAXPROCS. +// +// This can only be used as a best-effort facility; there is no guarantee that +// the goroutine still runs on the same P when this function returns. +func CurrentP() int { + // Note: preemption is not possible in-between these loads (there are no + // preemption-safe points). + return int(getg().m.p.ptr().id) +}