Skip to content

Commit c44c4de

Browse files
committed
internal/poll: use runtime.AddCleanup instead of runtime.SetFinalizer
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 <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent b4e992b commit c44c4de

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/internal/poll/splice_linux.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"runtime"
1010
"sync"
1111
"syscall"
12-
"unsafe"
1312
)
1413

1514
const (
@@ -179,10 +178,7 @@ type splicePipeFields struct {
179178

180179
type splicePipe struct {
181180
splicePipeFields
182-
183-
// We want to use a finalizer, so ensure that the size is
184-
// large enough to not use the tiny allocator.
185-
_ [24 - unsafe.Sizeof(splicePipeFields{})%24]byte
181+
cleanup runtime.Cleanup
186182
}
187183

188184
// splicePipePool caches pipes to avoid high-frequency construction and destruction of pipe buffers.
@@ -197,7 +193,10 @@ func newPoolPipe() any {
197193
if p == nil {
198194
return nil
199195
}
200-
runtime.SetFinalizer(p, destroyPipe)
196+
197+
p.cleanup = runtime.AddCleanup(p, func(spf splicePipeFields) {
198+
destroyPipe(&splicePipe{splicePipeFields: spf})
199+
}, p.splicePipeFields)
201200
return p
202201
}
203202

@@ -214,7 +213,7 @@ func putPipe(p *splicePipe) {
214213
// If there is still data left in the pipe,
215214
// then close and discard it instead of putting it back into the pool.
216215
if p.data != 0 {
217-
runtime.SetFinalizer(p, nil)
216+
p.cleanup.Stop()
218217
destroyPipe(p)
219218
return
220219
}

0 commit comments

Comments
 (0)