aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/debuglog.go
diff options
context:
space:
mode:
authorhopehook <hopehook.com@gmail.com>2022-08-26 11:28:48 +0800
committerMichael Knyszek <mknyszek@google.com>2022-08-26 15:35:46 +0000
commit2af9ee072788e91332ab7c2baa0fb568fd1e8545 (patch)
tree154024a3e8e0f3f8c78da5a381409a54501fe557 /src/runtime/debuglog.go
parent2883af63c28d1a4398cd60745d3c0cb7f7fbdacf (diff)
downloadgo-2af9ee072788e91332ab7c2baa0fb568fd1e8545.tar.xz
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 <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>
Diffstat (limited to 'src/runtime/debuglog.go')
-rw-r--r--src/runtime/debuglog.go8
1 files 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 (