aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/map_field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/map_field.cc')
-rw-r--r--src/google/protobuf/map_field.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/google/protobuf/map_field.cc b/src/google/protobuf/map_field.cc
index fd40c0d8..6ff1936e 100644
--- a/src/google/protobuf/map_field.cc
+++ b/src/google/protobuf/map_field.cc
@@ -104,14 +104,18 @@ void MapFieldBase::SetRepeatedDirty() { state_ = STATE_MODIFIED_REPEATED; }
void* MapFieldBase::MutableRepeatedPtrField() const { return repeated_field_; }
void MapFieldBase::SyncRepeatedFieldWithMap() const {
- Atomic32 state = google::protobuf::internal::NoBarrier_Load(&state_);
+ // "Acquire" insures the operation after SyncRepeatedFieldWithMap won't get
+ // executed before state_ is checked.
+ Atomic32 state = google::protobuf::internal::Acquire_Load(&state_);
if (state == STATE_MODIFIED_MAP) {
mutex_.Lock();
// Double check state, because another thread may have seen the same state
// and done the synchronization before the current thread.
if (state_ == STATE_MODIFIED_MAP) {
SyncRepeatedFieldWithMapNoLock();
- google::protobuf::internal::NoBarrier_Store(&state_, CLEAN);
+ // "Release" insures state_ can only be changed "after"
+ // SyncRepeatedFieldWithMapNoLock is finished.
+ google::protobuf::internal::Release_Store(&state_, CLEAN);
}
mutex_.Unlock();
}
@@ -119,19 +123,23 @@ void MapFieldBase::SyncRepeatedFieldWithMap() const {
void MapFieldBase::SyncRepeatedFieldWithMapNoLock() const {
if (repeated_field_ == NULL) {
- repeated_field_ = Arena::Create<RepeatedPtrField<Message> >(arena_, arena_);
+ repeated_field_ = Arena::CreateMessage<RepeatedPtrField<Message> >(arena_);
}
}
void MapFieldBase::SyncMapWithRepeatedField() const {
- Atomic32 state = google::protobuf::internal::NoBarrier_Load(&state_);
+ // "Acquire" insures the operation after SyncMapWithRepeatedField won't get
+ // executed before state_ is checked.
+ Atomic32 state = google::protobuf::internal::Acquire_Load(&state_);
if (state == STATE_MODIFIED_REPEATED) {
mutex_.Lock();
// Double check state, because another thread may have seen the same state
// and done the synchronization before the current thread.
if (state_ == STATE_MODIFIED_REPEATED) {
SyncMapWithRepeatedFieldNoLock();
- google::protobuf::internal::NoBarrier_Store(&state_, CLEAN);
+ // "Release" insures state_ can only be changed "after"
+ // SyncRepeatedFieldWithMapNoLock is finished.
+ google::protobuf::internal::Release_Store(&state_, CLEAN);
}
mutex_.Unlock();
}