]> Cypherpunks.ru repositories - gostls13.git/commitdiff
context: Revert "context: use CompareAndSwap in cancelCtx.Done"
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 8 Aug 2022 14:51:01 +0000 (21:51 +0700)
committerGopher Robot <gobot@golang.org>
Mon, 8 Aug 2022 16:05:18 +0000 (16:05 +0000)
This reverts commit 964f0c7a306998256f1c5a5fd78fc457a972f001.

Reason: cause increasing timeout in crypto/tls tests on race builders.

Change-Id: Id16d4fcd19c2ca2e89ad4d0c9d55ef1105b19c76
Reviewed-on: https://go-review.googlesource.com/c/go/+/422035
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/context/context.go

index 04ac080402afce44eb3672e7c8a2971ee7738033..1070111efa59384393944e629a411ffcec3765b4 100644 (file)
@@ -360,8 +360,14 @@ func (c *cancelCtx) Done() <-chan struct{} {
        if d != nil {
                return d.(chan struct{})
        }
-       c.done.CompareAndSwap(nil, make(chan struct{}))
-       return c.done.Load().(chan struct{})
+       c.mu.Lock()
+       defer c.mu.Unlock()
+       d = c.done.Load()
+       if d == nil {
+               d = make(chan struct{})
+               c.done.Store(d)
+       }
+       return d.(chan struct{})
 }
 
 func (c *cancelCtx) Err() error {