feat: CompareAndSwapInt32 may be better than AddInt32 (#2077)

This commit is contained in:
wxc 2022-07-01 12:41:32 +08:00 committed by GitHub
parent ce7e2a2a9a
commit d200ba4a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -376,9 +376,7 @@ type onceChan struct {
}
func (oc *onceChan) write(val interface{}) {
if atomic.AddInt32(&oc.wrote, 1) > 1 {
return
if atomic.CompareAndSwapInt32(&oc.wrote, 0, 1) {
oc.channel <- val
}
oc.channel <- val
}