github.com/TeaOSLab/EdgeNode@v1.3.8/internal/compressions/reader_base.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package compressions
     4  
     5  import "sync/atomic"
     6  
     7  type BaseReader struct {
     8  	pool *ReaderPool
     9  
    10  	isFinished bool
    11  	hits       uint32
    12  }
    13  
    14  func (this *BaseReader) SetPool(pool *ReaderPool) {
    15  	this.pool = pool
    16  }
    17  
    18  func (this *BaseReader) Finish(obj Reader) error {
    19  	if this.isFinished {
    20  		return nil
    21  	}
    22  	err := obj.RawClose()
    23  	if err == nil && this.pool != nil {
    24  		this.pool.Put(obj)
    25  	}
    26  	this.isFinished = true
    27  	return err
    28  }
    29  
    30  func (this *BaseReader) ResetFinish() {
    31  	this.isFinished = false
    32  }
    33  
    34  func (this *BaseReader) IncreaseHit() uint32 {
    35  	return atomic.AddUint32(&this.hits, 1)
    36  }