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

master
wxc 2 years ago committed by GitHub
parent ce7e2a2a9a
commit d200ba4a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
} }

Loading…
Cancel
Save