Skip to content

Commit

Permalink
feat: CompareAndSwapInt32 may be better than AddInt32 (#2077)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxc421 committed Jul 1, 2022
1 parent ce7e2a2 commit d200ba4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions core/mr/mapreduce.go
Expand Up @@ -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
}

0 comments on commit d200ba4

Please sign in to comment.