From 2af9ee072788e91332ab7c2baa0fb568fd1e8545 Mon Sep 17 00:00:00 2001 From: hopehook Date: Fri, 26 Aug 2022 11:28:48 +0800 Subject: [PATCH] runtime: convert dlogger.owned to atomic type Note that this changes a non-atomic operation to atomic operation. For #53821 Change-Id: I798914f505c8d7f85f9d7629fdc6493363a20aa1 Reviewed-on: https://go-review.googlesource.com/c/go/+/425782 Run-TryBot: Michael Pratt Reviewed-by: Michael Knyszek Run-TryBot: hopehook TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt --- src/runtime/debuglog.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/debuglog.go b/src/runtime/debuglog.go index 904d8983f6..028d77ad41 100644 --- a/src/runtime/debuglog.go +++ b/src/runtime/debuglog.go @@ -64,7 +64,7 @@ func dlog() *dlogger { allp := (*uintptr)(unsafe.Pointer(&allDloggers)) all := (*dlogger)(unsafe.Pointer(atomic.Loaduintptr(allp))) for l1 := all; l1 != nil; l1 = l1.allLink { - if atomic.Load(&l1.owned) == 0 && atomic.Cas(&l1.owned, 0, 1) { + if l1.owned.Load() == 0 && l1.owned.CompareAndSwap(0, 1) { l = l1 break } @@ -80,7 +80,7 @@ func dlog() *dlogger { throw("failed to allocate debug log") } l.w.r.data = &l.w.data - l.owned = 1 + l.owned.Store(1) // Prepend to allDloggers list. headp := (*uintptr)(unsafe.Pointer(&allDloggers)) @@ -131,7 +131,7 @@ type dlogger struct { // owned indicates that this dlogger is owned by an M. This is // accessed atomically. - owned uint32 + owned atomic.Uint32 } // allDloggers is a list of all dloggers, linked through @@ -160,7 +160,7 @@ func (l *dlogger) end() { } // Return the logger to the global pool. - atomic.Store(&l.owned, 0) + l.owned.Store(0) } const ( -- 2.50.0