summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/priorityqueue/binary_heap.go6
-rw-r--r--pkg/priorityqueue/interface.go1
2 files changed, 6 insertions, 1 deletions
diff --git a/pkg/priorityqueue/binary_heap.go b/pkg/priorityqueue/binary_heap.go
index 47fdf5e5..a8d80fc0 100644
--- a/pkg/priorityqueue/binary_heap.go
+++ b/pkg/priorityqueue/binary_heap.go
@@ -68,6 +68,10 @@ func (bh *BinHeap) fixDown(curr, end int) {
}
}
+func (bh *BinHeap) Len() uint64 {
+ return atomic.LoadUint64(&bh.len)
+}
+
func (bh *BinHeap) Insert(item Item) {
bh.cond.L.Lock()
bh.items = append(bh.items, item)
@@ -87,7 +91,7 @@ func (bh *BinHeap) GetMax() Item {
bh.cond.L.Lock()
defer bh.cond.L.Unlock()
- if atomic.LoadUint64(&bh.len) == 0 {
+ for atomic.LoadUint64(&bh.len) == 0 {
bh.cond.Wait()
}
diff --git a/pkg/priorityqueue/interface.go b/pkg/priorityqueue/interface.go
index 100aa667..7c053e6d 100644
--- a/pkg/priorityqueue/interface.go
+++ b/pkg/priorityqueue/interface.go
@@ -3,6 +3,7 @@ package priorityqueue
type Queue interface {
Insert(item Item)
GetMax() Item
+ Len() uint64
}
// Item represents binary heap item