don't acquire lock if there is no Ewma or Average decorators
Vladimir Bauer
6 years ago
| 33 | 33 | priority int // used by heap |
| 34 | 34 | index int // used by heap |
| 35 | 35 | |
| 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 | |
| 44 | 46 | |
| 45 | 47 | // cancel is called either by user or on complete event |
| 46 | 48 | cancel func() |
| 260 | 262 | // iteration's duration. Panics if called before *Bar.Incr... family |
| 261 | 263 | // methods. |
| 262 | 264 | func (b *Bar) DecoratorEwmaUpdate(dur time.Duration) { |
| 265 | if !b.hasEwmaDecorators { | |
| 266 | return | |
| 267 | } | |
| 263 | 268 | select { |
| 264 | 269 | case b.operateState <- func(s *bState) { |
| 265 | 270 | ewmaIterationUpdate(false, s, dur) |
| 273 | 278 | // if you need to adjust start time of all average based decorators |
| 274 | 279 | // or after progress resume. |
| 275 | 280 | func (b *Bar) DecoratorAverageAdjust(start time.Time) { |
| 281 | if !b.hasAverageDecorators { | |
| 282 | return | |
| 283 | } | |
| 276 | 284 | select { |
| 277 | 285 | case b.operateState <- func(s *bState) { |
| 278 | 286 | for _, d := range s.averageDecorators { |
| 395 | 403 | s.ewmaDecorators = ewmaDecorators |
| 396 | 404 | s.shutdownListeners = shutdownListeners |
| 397 | 405 | } |
| 406 | b.hasAverageDecorators = len(averageDecorators) != 0 | |
| 407 | b.hasEwmaDecorators = len(ewmaDecorators) != 0 | |
| 398 | 408 | } |
| 399 | 409 | |
| 400 | 410 | func (b *Bar) refreshTillShutdown() { |