2022-03-20 00:05:47 +08:00
|
|
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
|
|
|
|
|
|
package compressions
|
|
|
|
|
|
2024-04-16 11:32:38 +08:00
|
|
|
import "sync/atomic"
|
|
|
|
|
|
2022-03-20 00:05:47 +08:00
|
|
|
type BaseReader struct {
|
|
|
|
|
pool *ReaderPool
|
|
|
|
|
|
|
|
|
|
isFinished bool
|
2024-04-16 11:32:38 +08:00
|
|
|
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 {
|
2024-04-16 11:32:38 +08:00
|
|
|
if this.isFinished {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2022-03-20 00:05:47 +08:00
|
|
|
err := obj.RawClose()
|
2024-04-16 11:32:38 +08:00
|
|
|
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
|
|
|
|
|
}
|
2024-04-16 11:32:38 +08:00
|
|
|
|
|
|
|
|
func (this *BaseReader) IncreaseHit() uint32 {
|
|
|
|
|
return atomic.AddUint32(&this.hits, 1)
|
|
|
|
|
}
|