forked from cerc-io/plugeth
p2p: use safe atomic operations when changing connFlags (#17325)
This commit is contained in:
parent
c4df67461f
commit
eef65b20fc
@ -258,13 +258,18 @@ func (c *conn) is(f connFlag) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *conn) set(f connFlag, val bool) {
|
func (c *conn) set(f connFlag, val bool) {
|
||||||
flags := connFlag(atomic.LoadInt32((*int32)(&c.flags)))
|
for {
|
||||||
if val {
|
oldFlags := connFlag(atomic.LoadInt32((*int32)(&c.flags)))
|
||||||
flags |= f
|
flags := oldFlags
|
||||||
} else {
|
if val {
|
||||||
flags &= ^f
|
flags |= f
|
||||||
|
} else {
|
||||||
|
flags &= ^f
|
||||||
|
}
|
||||||
|
if atomic.CompareAndSwapInt32((*int32)(&c.flags), int32(oldFlags), int32(flags)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
atomic.StoreInt32((*int32)(&c.flags), int32(flags))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peers returns all connected peers.
|
// Peers returns all connected peers.
|
||||||
|
Loading…
Reference in New Issue
Block a user