Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uint32 atomics #46

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (a *Announce) String() string {
}

// Returns the number of distinct remote addresses the announce has queried.
func (a *Announce) NumContacted() int64 {
return atomic.LoadInt64(&a.traversal.Stats().NumAddrsTried)
func (a *Announce) NumContacted() uint32 {
return atomic.LoadUint32(&a.traversal.Stats().NumAddrsTried)
}

type AnnounceOpt *struct{}
Expand Down
4 changes: 2 additions & 2 deletions traversal/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (op *Operation) startQuery() {
op.cond.Broadcast()
}()
//log.Printf("traversal querying %v", a)
atomic.AddInt64(&op.stats.NumAddrsTried, 1)
atomic.AddUint32(&op.stats.NumAddrsTried, 1)
ctx, cancel := context.WithCancel(context.Background())
go func() {
select {
Expand All @@ -221,7 +221,7 @@ func (op *Operation) startQuery() {
func() {
op.mu.Lock()
defer op.mu.Unlock()
atomic.AddInt64(&op.stats.NumResponses, 1)
atomic.AddUint32(&op.stats.NumResponses, 1)
op.addClosest(*res.ResponseFrom, res.ClosestData)
}()
}
Expand Down
4 changes: 2 additions & 2 deletions traversal/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

type Stats struct {
// Count of (probably) distinct addresses we've sent traversal queries to. Accessed with atomic.
NumAddrsTried int64
NumAddrsTried uint32
// Number of responses we received to queries related to this traversal. Accessed with atomic.
NumResponses int64
NumResponses uint32
}

func (me Stats) String() string {
Expand Down