Skip to content

Commit

Permalink
Use uint32 atomics
Browse files Browse the repository at this point in the history
int64 atomics are not supported on 32-bit systems as of now: golang/go#599
  • Loading branch information
afjoseph committed Sep 1, 2021
1 parent df499f4 commit 8ddea2e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions announce.go
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
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
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

0 comments on commit 8ddea2e

Please sign in to comment.