cmd/devp2p: atomic types used (#27755)

pull/27767/head
ucwong 1 year ago committed by GitHub
parent 7a1fba1a02
commit a196f3e8a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      cmd/devp2p/crawl.go

@ -87,11 +87,11 @@ func (c *crawler) run(timeout time.Duration, nthreads int) nodeSet {
go c.runIterator(doneCh, it) go c.runIterator(doneCh, it)
} }
var ( var (
added uint64 added atomic.Uint64
updated uint64 updated atomic.Uint64
skipped uint64 skipped atomic.Uint64
recent uint64 recent atomic.Uint64
removed uint64 removed atomic.Uint64
wg sync.WaitGroup wg sync.WaitGroup
) )
wg.Add(nthreads) wg.Add(nthreads)
@ -103,15 +103,15 @@ func (c *crawler) run(timeout time.Duration, nthreads int) nodeSet {
case n := <-c.ch: case n := <-c.ch:
switch c.updateNode(n) { switch c.updateNode(n) {
case nodeSkipIncompat: case nodeSkipIncompat:
atomic.AddUint64(&skipped, 1) skipped.Add(1)
case nodeSkipRecent: case nodeSkipRecent:
atomic.AddUint64(&recent, 1) recent.Add(1)
case nodeRemoved: case nodeRemoved:
atomic.AddUint64(&removed, 1) removed.Add(1)
case nodeAdded: case nodeAdded:
atomic.AddUint64(&added, 1) added.Add(1)
default: default:
atomic.AddUint64(&updated, 1) updated.Add(1)
} }
case <-c.closed: case <-c.closed:
return return
@ -138,11 +138,11 @@ loop:
break loop break loop
case <-statusTicker.C: case <-statusTicker.C:
log.Info("Crawling in progress", log.Info("Crawling in progress",
"added", atomic.LoadUint64(&added), "added", added.Load(),
"updated", atomic.LoadUint64(&updated), "updated", updated.Load(),
"removed", atomic.LoadUint64(&removed), "removed", removed.Load(),
"ignored(recent)", atomic.LoadUint64(&recent), "ignored(recent)", recent.Load(),
"ignored(incompatible)", atomic.LoadUint64(&skipped)) "ignored(incompatible)", skipped.Load())
} }
} }

Loading…
Cancel
Save