@@ -65,10 +65,13 @@ const (
65
65
// to a queue, which gets picked up by the Render logic in the next rendering
66
66
// cycle.
67
67
func (p * Progress ) AppendTracker (t * Tracker ) {
68
+ t .mutex .Lock ()
68
69
if t .Total < 0 {
69
70
t .Total = math .MaxInt64
70
71
}
72
+ t .mutex .Unlock ()
71
73
t .start ()
74
+
72
75
p .overallTrackerMutex .Lock ()
73
76
if p .overallTracker == nil {
74
77
p .overallTracker = & Tracker {Total : 1 }
@@ -109,38 +112,42 @@ func (p *Progress) Length() int {
109
112
p .trackersActiveMutex .RLock ()
110
113
p .trackersDoneMutex .RLock ()
111
114
p .trackersInQueueMutex .RLock ()
112
- defer p .trackersActiveMutex .RUnlock ()
113
- defer p .trackersDoneMutex .RUnlock ()
114
- defer p .trackersInQueueMutex .RUnlock ()
115
+ out := len (p .trackersInQueue ) + len (p .trackersActive ) + len (p .trackersDone )
116
+ p .trackersInQueueMutex .RUnlock ()
117
+ p .trackersDoneMutex .RUnlock ()
118
+ p .trackersActiveMutex .RUnlock ()
115
119
116
- return len ( p . trackersInQueue ) + len ( p . trackersActive ) + len ( p . trackersDone )
120
+ return out
117
121
}
118
122
119
123
// LengthActive returns the number of Trackers actively tracked (not done yet).
120
124
func (p * Progress ) LengthActive () int {
121
125
p .trackersActiveMutex .RLock ()
122
126
p .trackersInQueueMutex .RLock ()
123
- defer p .trackersActiveMutex .RUnlock ()
124
- defer p .trackersInQueueMutex .RUnlock ()
127
+ out := len (p .trackersInQueue ) + len (p .trackersActive )
128
+ p .trackersInQueueMutex .RUnlock ()
129
+ p .trackersActiveMutex .RUnlock ()
125
130
126
- return len ( p . trackersInQueue ) + len ( p . trackersActive )
131
+ return out
127
132
}
128
133
129
134
// LengthDone returns the number of Trackers that are done tracking.
130
135
func (p * Progress ) LengthDone () int {
131
136
p .trackersDoneMutex .RLock ()
132
- defer p .trackersDoneMutex .RUnlock ()
137
+ out := len (p .trackersDone )
138
+ p .trackersDoneMutex .RUnlock ()
133
139
134
- return len ( p . trackersDone )
140
+ return out
135
141
}
136
142
137
143
// LengthInQueue returns the number of Trackers in queue to be actively tracked
138
144
// (not tracking yet).
139
145
func (p * Progress ) LengthInQueue () int {
140
146
p .trackersInQueueMutex .RLock ()
141
- defer p .trackersInQueueMutex .RUnlock ()
147
+ out := len (p .trackersInQueue )
148
+ p .trackersInQueueMutex .RUnlock ()
142
149
143
- return len ( p . trackersInQueue )
150
+ return out
144
151
}
145
152
146
153
// SetAutoStop toggles the auto-stop functionality. Auto-stop set to true would
0 commit comments