Codebase list golang-github-vbauerster-mpb / f0681a7
don't acquire lock if there is no Ewma or Average decorators Vladimir Bauer 6 years ago
1 changed file(s) with 18 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
3333 priority int // used by heap
3434 index int // used by heap
3535
36 extendedLines int
37 toShutdown bool
38 toDrop bool
39 noPop bool
40 operateState chan func(*bState)
41 frameCh chan io.Reader
42 syncTableCh chan [][]chan int
43 completed chan bool
36 extendedLines int
37 toShutdown bool
38 toDrop bool
39 noPop bool
40 hasAverageDecorators bool
41 hasEwmaDecorators bool
42 operateState chan func(*bState)
43 frameCh chan io.Reader
44 syncTableCh chan [][]chan int
45 completed chan bool
4446
4547 // cancel is called either by user or on complete event
4648 cancel func()
260262 // iteration's duration. Panics if called before *Bar.Incr... family
261263 // methods.
262264 func (b *Bar) DecoratorEwmaUpdate(dur time.Duration) {
265 if !b.hasEwmaDecorators {
266 return
267 }
263268 select {
264269 case b.operateState <- func(s *bState) {
265270 ewmaIterationUpdate(false, s, dur)
273278 // if you need to adjust start time of all average based decorators
274279 // or after progress resume.
275280 func (b *Bar) DecoratorAverageAdjust(start time.Time) {
281 if !b.hasAverageDecorators {
282 return
283 }
276284 select {
277285 case b.operateState <- func(s *bState) {
278286 for _, d := range s.averageDecorators {
395403 s.ewmaDecorators = ewmaDecorators
396404 s.shutdownListeners = shutdownListeners
397405 }
406 b.hasAverageDecorators = len(averageDecorators) != 0
407 b.hasEwmaDecorators = len(ewmaDecorators) != 0
398408 }
399409
400410 func (b *Bar) refreshTillShutdown() {