From 8a3d167f5b4b482a230cd9800df9969af60561af Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sat, 27 Aug 2022 10:35:31 +0800 Subject: [PATCH] testing: increment tempDirSeq non-atomically It's unnecessary to to call atomic.AddInt32 since there is a mutex lock. Change-Id: I31fcece17c34f99a95772d744aebd3f6a8cf1d23 Reviewed-on: https://go-review.googlesource.com/c/go/+/426081 Reviewed-by: Michael Pratt TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Reviewed-by: Bryan Mills Reviewed-by: Heschi Kreinick Auto-Submit: Bryan Mills --- src/testing/testing.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/testing/testing.go b/src/testing/testing.go index 7148537370..0228d2904b 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -1127,12 +1127,17 @@ func (c *common) TempDir() string { }) } } + + if c.tempDirErr == nil { + c.tempDirSeq++ + } + seq := c.tempDirSeq c.tempDirMu.Unlock() if c.tempDirErr != nil { c.Fatalf("TempDir: %v", c.tempDirErr) } - seq := atomic.AddInt32(&c.tempDirSeq, 1) + dir := fmt.Sprintf("%s%c%03d", c.tempDir, os.PathSeparator, seq) if err := os.Mkdir(dir, 0777); err != nil { c.Fatalf("TempDir: %v", err) -- 2.48.1