Ver código fonte

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

wxc 2 anos atrás
pai
commit
d200ba4a7b
1 arquivos alterados com 2 adições e 4 exclusões
  1. 2 4
      core/mr/mapreduce.go

+ 2 - 4
core/mr/mapreduce.go

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