Skip to content

Commit 6d2bcb9

Browse files
authored
p2p/simulations/examples: use atomic.Int64 (#27861)
1 parent eeebb07 commit 6d2bcb9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

p2p/simulations/examples/ping-pong.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func main() {
9191
type pingPongService struct {
9292
id enode.ID
9393
log log.Logger
94-
received int64
94+
received atomic.Int64
9595
}
9696

9797
func newPingPongService(id enode.ID) *pingPongService {
@@ -125,7 +125,7 @@ func (p *pingPongService) Info() interface{} {
125125
return struct {
126126
Received int64 `json:"received"`
127127
}{
128-
atomic.LoadInt64(&p.received),
128+
p.received.Load(),
129129
}
130130
}
131131

@@ -162,7 +162,7 @@ func (p *pingPongService) Run(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
162162
return
163163
}
164164
log.Info("received message", "msg.code", msg.Code, "msg.payload", string(payload))
165-
atomic.AddInt64(&p.received, 1)
165+
p.received.Add(1)
166166
if msg.Code == pingMsgCode {
167167
log.Info("sending pong")
168168
go p2p.Send(rw, pongMsgCode, "PONG")

0 commit comments

Comments
 (0)