From d200ba4a7b009fc8d5d1417e8ff6f870e65a9506 Mon Sep 17 00:00:00 2001 From: wxc <53962888+wxc421@users.noreply.github.com> Date: Fri, 1 Jul 2022 12:41:32 +0800 Subject: [PATCH] feat: CompareAndSwapInt32 may be better than AddInt32 (#2077) --- core/mr/mapreduce.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/mr/mapreduce.go b/core/mr/mapreduce.go index 23d70bd0..5e78e846 100644 --- a/core/mr/mapreduce.go +++ b/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 }