1
0
mirror of https://github.com/golang/go synced 2024-11-17 01:34:52 -07:00

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>
This commit is contained in:
hopehook 2022-08-26 11:28:48 +08:00 committed by Michael Knyszek
parent 2883af63c2
commit 2af9ee0727

View 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 (