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