Skip to content

Commit

Permalink
swarm: use typed atomics
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 20, 2023
1 parent f549314 commit 55ac231
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions p2p/net/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func WithIPv6BlackHoleConfig(enabled bool, n, min int) Option {
// communication. The Chan sends/receives Messages, which note the
// destination or source Peer.
type Swarm struct {
nextConnID uint64 // guarded by atomic
nextStreamID uint64 // guarded by atomic
nextConnID atomic.Uint64
nextStreamID atomic.Uint64

// Close refcount. This allows us to fully wait for the swarm to be torn
// down before continuing.
Expand Down Expand Up @@ -350,7 +350,7 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn,
conn: tc,
swarm: s,
stat: stat,
id: atomic.AddUint64(&s.nextConnID, 1),
id: s.nextConnID.Add(1),
}

// we ONLY check upgraded connections here so we can send them a Disconnect message.
Expand Down
3 changes: 1 addition & 2 deletions p2p/net/swarm/swarm_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"sync"
"sync/atomic"
"time"

ic "github.com/libp2p/go-libp2p/core/crypto"
Expand Down Expand Up @@ -239,7 +238,7 @@ func (c *Conn) addStream(ts network.MuxedStream, dir network.Direction, scope ne
Direction: dir,
Opened: time.Now(),
},
id: atomic.AddUint64(&c.swarm.nextStreamID, 1),
id: c.swarm.nextStreamID.Add(1),
acceptStreamGoroutineCompleted: dir != network.DirInbound,
}
c.stat.NumStreams++
Expand Down

0 comments on commit 55ac231

Please sign in to comment.