From: Cuong Manh Le Date: Mon, 8 Aug 2022 14:51:01 +0000 (+0700) Subject: context: Revert "context: use CompareAndSwap in cancelCtx.Done" X-Git-Tag: go1.20rc1~1776 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=487b3501a54e5479972a7982fe1eb154f0447b58;p=gostls13.git context: Revert "context: use CompareAndSwap in cancelCtx.Done" 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 Reviewed-by: Than McIntosh Auto-Submit: Cuong Manh Le Run-TryBot: Cuong Manh Le Reviewed-by: Michael Pratt --- diff --git a/src/context/context.go b/src/context/context.go index 04ac080402..1070111efa 100644 --- a/src/context/context.go +++ b/src/context/context.go @@ -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 {