Files
EdgeNode/internal/compressions/reader_base.go

37 lines
638 B
Go
Raw Normal View History

2024-05-17 18:30:33 +08:00
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
2022-03-20 00:05:47 +08:00
package compressions
import "sync/atomic"
2022-03-20 00:05:47 +08:00
type BaseReader struct {
pool *ReaderPool
isFinished bool
hits uint32
2022-03-20 00:05:47 +08:00
}
func (this *BaseReader) SetPool(pool *ReaderPool) {
this.pool = pool
}
func (this *BaseReader) Finish(obj Reader) error {
if this.isFinished {
return nil
}
2022-03-20 00:05:47 +08:00
err := obj.RawClose()
if err == nil && this.pool != nil {
2022-03-20 00:05:47 +08:00
this.pool.Put(obj)
}
this.isFinished = true
return err
}
func (this *BaseReader) ResetFinish() {
this.isFinished = false
}
func (this *BaseReader) IncreaseHit() uint32 {
return atomic.AddUint32(&this.hits, 1)
}