Skip to content

Commit be34045

Browse files
committed
Merge pull request #103 from jlhonora/master
Priority queue cleanup
2 parents 023c25a + a942133 commit be34045

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

queue/priority_queue.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ func (pq *PriorityQueue) Put(items ...Item) error {
120120
}
121121

122122
pq.lock.Lock()
123+
defer pq.lock.Unlock()
124+
123125
if pq.disposed {
124-
pq.lock.Unlock()
125126
return ErrDisposed
126127
}
127128

@@ -146,7 +147,6 @@ func (pq *PriorityQueue) Put(items ...Item) error {
146147
}
147148
}
148149

149-
pq.lock.Unlock()
150150
return nil
151151
}
152152

@@ -180,12 +180,10 @@ func (pq *PriorityQueue) Get(number int) ([]Item, error) {
180180
pq.lock.Unlock()
181181

182182
<-sema.ready
183-
pq.disposeLock.Lock()
184-
if pq.disposed {
185-
pq.disposeLock.Unlock()
183+
184+
if pq.Disposed() {
186185
return nil, ErrDisposed
187186
}
188-
pq.disposeLock.Unlock()
189187

190188
items = pq.items.get(number)
191189
deleteItems(items)
@@ -228,8 +226,8 @@ func (pq *PriorityQueue) Len() int {
228226

229227
// Disposed returns a bool indicating if this queue has been disposed.
230228
func (pq *PriorityQueue) Disposed() bool {
231-
pq.lock.Lock()
232-
defer pq.lock.Unlock()
229+
pq.disposeLock.Lock()
230+
defer pq.disposeLock.Unlock()
233231

234232
return pq.disposed
235233
}

0 commit comments

Comments
 (0)