diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-05-16 16:45:47 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-05-16 15:38:27 +0000 |
| commit | ad5321c6e31dd6b723935e195830789efdda12c5 (patch) | |
| tree | a30f2685279b622de2ac8ff0b67974adf4e2a2c4 /pkg/fuzzer/queue | |
| parent | dc6371ad7762a2246c525a6b4830455c38178e97 (diff) | |
pkg/fuzzer/queue: refactor DynamicSource
Use a simpler implementation.
Don't assume the nested Source may be nil.
Diffstat (limited to 'pkg/fuzzer/queue')
| -rw-r--r-- | pkg/fuzzer/queue/queue.go | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/pkg/fuzzer/queue/queue.go b/pkg/fuzzer/queue/queue.go index 68552083c..0fd87f7c7 100644 --- a/pkg/fuzzer/queue/queue.go +++ b/pkg/fuzzer/queue/queue.go @@ -343,24 +343,23 @@ func (pq *PriorityQueue) Next() *Request { return pq.ops.Pop() } -type DynamicSource struct { - value atomic.Pointer[wrapSource] +type DynamicSourceCtl struct { + value atomic.Pointer[Source] } -type wrapSource struct { - source Source +// DynamicSource is assumed never to point to nil. +func DynamicSource(source Source) *DynamicSourceCtl { + var ret DynamicSourceCtl + ret.Store(source) + return &ret } -func (ds *DynamicSource) Store(source Source) { - ds.value.Store(&wrapSource{source}) +func (ds *DynamicSourceCtl) Store(source Source) { + ds.value.Store(&source) } -func (ds *DynamicSource) Next() *Request { - val := ds.value.Load() - if val == nil || val.source == nil { - return nil - } - return val.source.Next() +func (ds *DynamicSourceCtl) Next() *Request { + return (*ds.value.Load()).Next() } // Deduplicator() keeps track of the previously run requests to avoid re-running them. |
