1
0
mirror of https://github.com/golang/go synced 2024-11-22 15:44:53 -07:00

internal/concurrent: remove dependency on math/rand/v2

This change uses linkname for the one random function
internal/concurrent needs to avoid taking a dependency on math/rand/v2.
This lowers the bar to using this package.

Change-Id: I9dba1121b66ba35f56521643937f220936ea5321
Reviewed-on: https://go-review.googlesource.com/c/go/+/594057
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Michael Anthony Knyszek 2024-06-21 17:07:28 +00:00 committed by Gopher Robot
parent 6c66005285
commit cea365ddfb
2 changed files with 9 additions and 6 deletions

View File

@ -103,7 +103,8 @@ var depsRules = `
< internal/godebug < internal/godebug
< internal/reflectlite < internal/reflectlite
< errors < errors
< internal/oserror; < internal/oserror
< internal/concurrent;
cmp, runtime, math/bits cmp, runtime, math/bits
< iter < iter
@ -164,9 +165,6 @@ var depsRules = `
MATH MATH
< runtime/metrics; < runtime/metrics;
RUNTIME, math/rand/v2
< internal/concurrent;
MATH, unicode/utf8 MATH, unicode/utf8
< strconv; < strconv;

View File

@ -7,7 +7,6 @@ package concurrent
import ( import (
"internal/abi" "internal/abi"
"internal/goarch" "internal/goarch"
"math/rand/v2"
"sync" "sync"
"sync/atomic" "sync/atomic"
"unsafe" "unsafe"
@ -34,7 +33,7 @@ func NewHashTrieMap[K, V comparable]() *HashTrieMap[K, V] {
keyHash: mapType.Hasher, keyHash: mapType.Hasher,
keyEqual: mapType.Key.Equal, keyEqual: mapType.Key.Equal,
valEqual: mapType.Elem.Equal, valEqual: mapType.Elem.Equal,
seed: uintptr(rand.Uint64()), seed: uintptr(runtime_rand()),
} }
return ht return ht
} }
@ -406,3 +405,9 @@ func (n *node[K, V]) indirect() *indirect[K, V] {
} }
return (*indirect[K, V])(unsafe.Pointer(n)) return (*indirect[K, V])(unsafe.Pointer(n))
} }
// Pull in runtime.rand so that we don't need to take a dependency
// on math/rand/v2.
//
//go:linkname runtime_rand runtime.rand
func runtime_rand() uint64