mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-29 12:17:48 +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) {
|
||||
switch m := m.(type) {
|
||||
case *messageState:
|
||||
return m.pointer(), m.mi == mi
|
||||
return m.pointer(), m.messageInfo() == mi
|
||||
case *messageReflectWrapper:
|
||||
return m.pointer(), m.mi == mi
|
||||
return m.pointer(), m.messageInfo() == mi
|
||||
}
|
||||
return pointer{}, false
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ type MessageState struct {
|
||||
pragma.DoNotCompare
|
||||
pragma.DoNotCopy
|
||||
|
||||
mi *MessageInfo
|
||||
atomicMessageInfo *MessageInfo
|
||||
}
|
||||
|
||||
type messageState MessageState
|
||||
|
@ -151,10 +151,10 @@ func (ms *messageState) messageInfo() *MessageInfo {
|
||||
return ms.LoadMessageInfo()
|
||||
}
|
||||
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) {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user