]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: use runtime.AddCleanup instead of runtime.SetFinalizer
authorCarlos Amedee <carlos@golang.org>
Fri, 9 May 2025 21:44:35 +0000 (17:44 -0400)
committerCarlos Amedee <carlos@golang.org>
Tue, 13 May 2025 21:03:05 +0000 (14:03 -0700)
Replace the use of SetFinalizer with AddCleanup.

For #70907

Change-Id: I0cb2c2985eb9285e5f92be9dbcb9d77acc0f59c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/671441
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/internal/poll/splice_linux.go

index 193a56215c727c75bd1b1a16dcd8c3853bc26aa3..4409d2f33600a4df25a85a12e931071845c3a871 100644 (file)
@@ -9,7 +9,6 @@ import (
        "runtime"
        "sync"
        "syscall"
-       "unsafe"
 )
 
 const (
@@ -179,10 +178,7 @@ type splicePipeFields struct {
 
 type splicePipe struct {
        splicePipeFields
-
-       // We want to use a finalizer, so ensure that the size is
-       // large enough to not use the tiny allocator.
-       _ [24 - unsafe.Sizeof(splicePipeFields{})%24]byte
+       cleanup runtime.Cleanup
 }
 
 // splicePipePool caches pipes to avoid high-frequency construction and destruction of pipe buffers.
@@ -197,7 +193,10 @@ func newPoolPipe() any {
        if p == nil {
                return nil
        }
-       runtime.SetFinalizer(p, destroyPipe)
+
+       p.cleanup = runtime.AddCleanup(p, func(spf splicePipeFields) {
+               destroyPipe(&splicePipe{splicePipeFields: spf})
+       }, p.splicePipeFields)
        return p
 }
 
@@ -214,7 +213,7 @@ func putPipe(p *splicePipe) {
        // If there is still data left in the pipe,
        // then close and discard it instead of putting it back into the pool.
        if p.data != 0 {
-               runtime.SetFinalizer(p, nil)
+               p.cleanup.Stop()
                destroyPipe(p)
                return
        }