File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed
Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ type Limits struct {
1313 addition uint64
1414 capacity uint64
1515 last time.Time
16- loop uint64
1716 mu sync.Mutex
1817 size uint64
1918 step time.Duration
@@ -25,19 +24,19 @@ func (l *Limits) Wait(n uint64) {
2524 doa .Doa (l .size <= l .capacity )
2625 l .mu .Lock ()
2726 defer l .mu .Unlock ()
28- l . loop = uint64 (time .Since (l .last ) / l .step )
29- if l . loop > 0 {
30- l .last = l .last .Add (l .step * time .Duration (l . loop ))
31- doa .Doa (l . loop <= math .MaxUint64 / l .addition )
32- doa .Doa (l .size <= math .MaxUint64 - l .addition * l . loop )
33- l .size = l .size + l .addition * l . loop
27+ cycles : = uint64 (time .Since (l .last ) / l .step )
28+ if cycles > 0 {
29+ l .last = l .last .Add (l .step * time .Duration (cycles ))
30+ doa .Doa (cycles <= math .MaxUint64 / l .addition )
31+ doa .Doa (l .size <= math .MaxUint64 - l .addition * cycles )
32+ l .size = l .size + l .addition * cycles
3433 l .size = min (l .size , l .capacity )
3534 }
3635 if l .size < n {
37- l . loop = (n - l .size + l .addition - 1 ) / l .addition
38- time .Sleep (l .step * time .Duration (l . loop ))
39- l .last = l .last .Add (l .step * time .Duration (l . loop ))
40- l .size = l .size + l .addition * l . loop
36+ cycles = (n - l .size + l .addition - 1 ) / l .addition
37+ time .Sleep (l .step * time .Duration (cycles ))
38+ l .last = l .last .Add (l .step * time .Duration (cycles ))
39+ l .size = l .size + l .addition * cycles
4140 }
4241 l .size -= n
4342}
You can’t perform that action at this time.
0 commit comments