]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert dlogger.owned to atomic type
authorhopehook <hopehook.com@gmail.com>
Fri, 26 Aug 2022 03:28:48 +0000 (11:28 +0800)
committerMichael Knyszek <mknyszek@google.com>
Fri, 26 Aug 2022 15:35:46 +0000 (15:35 +0000)
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 <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: hopehook <hopehook@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/debuglog.go

index 904d8983f6709da52b4a655a0e4fdcd374e7bad9..028d77ad41da79ef3a0eb1ce789be0c17f4424f9 100644 (file)
@@ -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 (