mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
feat: CompareAndSwapInt32 may be better than AddInt32 (#2077)
This commit is contained in:
parent
ce7e2a2a9a
commit
d200ba4a7b
@ -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…
Reference in New Issue
Block a user