aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/fuzzer/prio_queue.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-03-22 17:00:10 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-03-22 16:19:56 +0000
commit0ea90952bdac100bde3149fa2a7818ba7af943b4 (patch)
treef59a09690f04a0e0a38d36d5458509f3e5a57ae3 /pkg/fuzzer/prio_queue.go
parentfaed73b705cd066381011120625cd0cfd7028879 (diff)
pkg/fuzzer: remove async priority queue operations
We don't need them.
Diffstat (limited to 'pkg/fuzzer/prio_queue.go')
-rw-r--r--pkg/fuzzer/prio_queue.go29
1 files changed, 8 insertions, 21 deletions
diff --git a/pkg/fuzzer/prio_queue.go b/pkg/fuzzer/prio_queue.go
index ea8f448c9..cb35cebf7 100644
--- a/pkg/fuzzer/prio_queue.go
+++ b/pkg/fuzzer/prio_queue.go
@@ -24,41 +24,28 @@ func (p priority) greaterThan(other priority) bool {
type priorityQueue[T any] struct {
impl priorityQueueImpl[T]
- c *sync.Cond
+ mu sync.RWMutex
}
func makePriorityQueue[T any]() *priorityQueue[T] {
- return &priorityQueue[T]{
- c: sync.NewCond(&sync.Mutex{}),
- }
+ return &priorityQueue[T]{}
}
func (pq *priorityQueue[T]) Len() int {
- pq.c.L.Lock()
- defer pq.c.L.Unlock()
+ pq.mu.RLock()
+ defer pq.mu.RUnlock()
return pq.impl.Len()
}
func (pq *priorityQueue[T]) push(item *priorityQueueItem[T]) {
- pq.c.L.Lock()
- defer pq.c.L.Unlock()
+ pq.mu.Lock()
+ defer pq.mu.Unlock()
heap.Push(&pq.impl, item)
- pq.c.Signal()
-}
-
-// pop() blocks until there's input.
-func (pq *priorityQueue[T]) pop() *priorityQueueItem[T] {
- pq.c.L.Lock()
- defer pq.c.L.Unlock()
- for pq.impl.Len() == 0 {
- pq.c.Wait()
- }
- return heap.Pop(&pq.impl).(*priorityQueueItem[T])
}
func (pq *priorityQueue[T]) tryPop() *priorityQueueItem[T] {
- pq.c.L.Lock()
- defer pq.c.L.Unlock()
+ pq.mu.Lock()
+ defer pq.mu.Unlock()
if len(pq.impl) == 0 {
return nil
}