feat: CompareAndSwapInt32 may be better than AddInt32 (#2077)
This commit is contained in:
@@ -376,9 +376,7 @@ type onceChan struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (oc *onceChan) write(val interface{}) {
|
func (oc *onceChan) write(val interface{}) {
|
||||||
if atomic.AddInt32(&oc.wrote, 1) > 1 {
|
if atomic.CompareAndSwapInt32(&oc.wrote, 0, 1) {
|
||||||
return
|
oc.channel <- val
|
||||||
}
|
}
|
||||||
|
|
||||||
oc.channel <- val
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user