소스 검색

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

wxc 2 년 전
부모
커밋
d200ba4a7b
1개의 변경된 파일2개의 추가작업 그리고 4개의 파일을 삭제
  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
 }