]> Cypherpunks repositories - gostls13.git/commitdiff
testing: increment tempDirSeq non-atomically
authorcuiweixie <cuiweixie@gmail.com>
Sat, 27 Aug 2022 02:35:31 +0000 (10:35 +0800)
committerGopher Robot <gobot@golang.org>
Tue, 30 Aug 2022 19:42:56 +0000 (19:42 +0000)
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 <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

src/testing/testing.go

index 7148537370fa6e23c6ad71ff606ee3e619cf0af5..0228d2904b2c585193876b01c5db36ffaa9c10cd 100644 (file)
@@ -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)