File tree 1 file changed +6
-7
lines changed
1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change 9
9
"runtime"
10
10
"sync"
11
11
"syscall"
12
- "unsafe"
13
12
)
14
13
15
14
const (
@@ -179,10 +178,7 @@ type splicePipeFields struct {
179
178
180
179
type splicePipe struct {
181
180
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
186
182
}
187
183
188
184
// splicePipePool caches pipes to avoid high-frequency construction and destruction of pipe buffers.
@@ -197,7 +193,10 @@ func newPoolPipe() any {
197
193
if p == nil {
198
194
return nil
199
195
}
200
- runtime .SetFinalizer (p , destroyPipe )
196
+
197
+ p .cleanup = runtime .AddCleanup (p , func (spf splicePipeFields ) {
198
+ destroyPipe (& splicePipe {splicePipeFields : spf })
199
+ }, p .splicePipeFields )
201
200
return p
202
201
}
203
202
@@ -214,7 +213,7 @@ func putPipe(p *splicePipe) {
214
213
// If there is still data left in the pipe,
215
214
// then close and discard it instead of putting it back into the pool.
216
215
if p .data != 0 {
217
- runtime . SetFinalizer ( p , nil )
216
+ p . cleanup . Stop ( )
218
217
destroyPipe (p )
219
218
return
220
219
}
You can’t perform that action at this time.
0 commit comments