mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 11:58:21 +00:00
internal/impl: fix non-atomic access of MessageState.mi
MessageState's mi field must only be accessed via atomic operations. Rename the field to 'atomicMessageInfo' to make it incorrect access obvious. Fix one incorrect non-atomic access. Change-Id: If80343fb1b82186416f007ca5b340a4926b1cd3c Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/221419 Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
parent
a786db3a49
commit
075e0741aa
@ -100,9 +100,9 @@ func (mi *MessageInfo) initOnce() {
|
|||||||
func (mi *MessageInfo) getPointer(m pref.Message) (p pointer, ok bool) {
|
func (mi *MessageInfo) getPointer(m pref.Message) (p pointer, ok bool) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *messageState:
|
case *messageState:
|
||||||
return m.pointer(), m.mi == mi
|
return m.pointer(), m.messageInfo() == mi
|
||||||
case *messageReflectWrapper:
|
case *messageReflectWrapper:
|
||||||
return m.pointer(), m.mi == mi
|
return m.pointer(), m.messageInfo() == mi
|
||||||
}
|
}
|
||||||
return pointer{}, false
|
return pointer{}, false
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ type MessageState struct {
|
|||||||
pragma.DoNotCompare
|
pragma.DoNotCompare
|
||||||
pragma.DoNotCopy
|
pragma.DoNotCopy
|
||||||
|
|
||||||
mi *MessageInfo
|
atomicMessageInfo *MessageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type messageState MessageState
|
type messageState MessageState
|
||||||
|
@ -151,10 +151,10 @@ func (ms *messageState) messageInfo() *MessageInfo {
|
|||||||
return ms.LoadMessageInfo()
|
return ms.LoadMessageInfo()
|
||||||
}
|
}
|
||||||
func (ms *messageState) LoadMessageInfo() *MessageInfo {
|
func (ms *messageState) LoadMessageInfo() *MessageInfo {
|
||||||
return (*MessageInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&ms.mi))))
|
return (*MessageInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&ms.atomicMessageInfo))))
|
||||||
}
|
}
|
||||||
func (ms *messageState) StoreMessageInfo(mi *MessageInfo) {
|
func (ms *messageState) StoreMessageInfo(mi *MessageInfo) {
|
||||||
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&ms.mi)), unsafe.Pointer(mi))
|
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&ms.atomicMessageInfo)), unsafe.Pointer(mi))
|
||||||
}
|
}
|
||||||
|
|
||||||
type atomicNilMessage struct{ p unsafe.Pointer } // p is a *messageReflectWrapper
|
type atomicNilMessage struct{ p unsafe.Pointer } // p is a *messageReflectWrapper
|
||||||
|
Loading…
Reference in New Issue
Block a user