aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mgc.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2024-04-04 04:51:24 +0000
committerMichael Knyszek <mknyszek@google.com>2024-04-22 18:14:07 +0000
commita088e230d4e7892b15851babe161bbd1766738a1 (patch)
treeb42bda131142e51a16e6327bb505849a4e60d474 /src/runtime/mgc.go
parent654c3368e53c923acff5fd5a1eaf4175bb6834d6 (diff)
downloadgo-a088e230d4e7892b15851babe161bbd1766738a1.tar.gz
go-a088e230d4e7892b15851babe161bbd1766738a1.zip
unique: add unique package and implement Make/Handle
This change adds the unique package for canonicalizing values, as described by the proposal in #62483. Fixes #62483. Change-Id: I1dc3d34ec12351cb4dc3838a8ea29a5368d59e99 Reviewed-on: https://go-review.googlesource.com/c/go/+/574355 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ingo Oeser <nightlyone@googlemail.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/runtime/mgc.go')
-rw-r--r--src/runtime/mgc.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go
index 3d3ecb0f88..83afd55c47 100644
--- a/src/runtime/mgc.go
+++ b/src/runtime/mgc.go
@@ -1694,7 +1694,8 @@ func gcResetMarkState() {
// Hooks for other packages
var poolcleanup func()
-var boringCaches []unsafe.Pointer // for crypto/internal/boring
+var boringCaches []unsafe.Pointer // for crypto/internal/boring
+var uniqueMapCleanup chan struct{} // for unique
//go:linkname sync_runtime_registerPoolCleanup sync.runtime_registerPoolCleanup
func sync_runtime_registerPoolCleanup(f func()) {
@@ -1706,6 +1707,18 @@ func boring_registerCache(p unsafe.Pointer) {
boringCaches = append(boringCaches, p)
}
+//go:linkname unique_runtime_registerUniqueMapCleanup unique.runtime_registerUniqueMapCleanup
+func unique_runtime_registerUniqueMapCleanup(f func()) {
+ // Start the goroutine in the runtime so it's counted as a system goroutine.
+ uniqueMapCleanup = make(chan struct{}, 1)
+ go func(cleanup func()) {
+ for {
+ <-uniqueMapCleanup
+ cleanup()
+ }
+ }(f)
+}
+
func clearpools() {
// clear sync.Pools
if poolcleanup != nil {
@@ -1717,6 +1730,14 @@ func clearpools() {
atomicstorep(p, nil)
}
+ // clear unique maps
+ if uniqueMapCleanup != nil {
+ select {
+ case uniqueMapCleanup <- struct{}{}:
+ default:
+ }
+ }
+
// Clear central sudog cache.
// Leave per-P caches alone, they have strictly bounded size.
// Disconnect cached list before dropping it on the floor,