Forráskód Böngészése

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

wxc 2 éve
szülő
commit
d200ba4a7b
1 módosított fájl, 2 hozzáadás és 4 törlés
  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
 }