Skip to content

Commit 26292e1

Browse files
committed
bug fix
1 parent 5a9dce0 commit 26292e1

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

queue.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func (q *queue) append(data interface{}, priority QueuePriority) {
8989

9090
// Signal implements the Queue interface.
9191
func (q *queue) Signal() <-chan struct{} {
92+
q.Lock()
93+
defer q.Unlock()
94+
9295
q.prepSignal()
9396
return q.signal
9497
}
@@ -101,7 +104,7 @@ func (q *queue) prepSignal() {
101104
default:
102105
}
103106

104-
if !send && q.Len() > 0 {
107+
if !send && q.lenWithoutLock() > 0 {
105108
send = true
106109
}
107110
if send {
@@ -113,12 +116,11 @@ func (q *queue) prepSignal() {
113116
}
114117

115118
func (q *queue) drain() {
116-
loop:
117119
for {
118120
select {
119121
case <-q.signal:
120122
default:
121-
break loop
123+
return
122124
}
123125
}
124126
}
@@ -146,6 +148,7 @@ func (q *queue) Next() (interface{}, bool) {
146148
return nil, false
147149
}
148150

151+
q.prepSignal()
149152
return data, true
150153
}
151154

@@ -169,10 +172,13 @@ func (q *queue) Len() int {
169172
q.Lock()
170173
defer q.Unlock()
171174

175+
return q.lenWithoutLock()
176+
}
177+
178+
func (q *queue) lenWithoutLock() int {
172179
qlen := len(q.low)
173180
qlen += len(q.norm)
174181
qlen += len(q.high)
175182
qlen += len(q.crit)
176-
177183
return qlen
178184
}

0 commit comments

Comments
 (0)