Commit eef65b20 authored by Felföldi Zsolt's avatar Felföldi Zsolt Committed by Péter Szilágyi

p2p: use safe atomic operations when changing connFlags (#17325)

parent c4df6746
......@@ -258,13 +258,18 @@ func (c *conn) is(f connFlag) bool {
}
func (c *conn) set(f connFlag, val bool) {
flags := connFlag(atomic.LoadInt32((*int32)(&c.flags)))
for {
oldFlags := connFlag(atomic.LoadInt32((*int32)(&c.flags)))
flags := oldFlags
if val {
flags |= f
} else {
flags &= ^f
}
atomic.StoreInt32((*int32)(&c.flags), int32(flags))
if atomic.CompareAndSwapInt32((*int32)(&c.flags), int32(oldFlags), int32(flags)) {
return
}
}
}
// Peers returns all connected peers.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment