diff options
Diffstat (limited to 'src/google/protobuf/map_field.h')
-rw-r--r-- | src/google/protobuf/map_field.h | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index 6c75a6da..44ca29b3 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -31,7 +31,8 @@ #ifndef GOOGLE_PROTOBUF_MAP_FIELD_H__ #define GOOGLE_PROTOBUF_MAP_FIELD_H__ -#include <google/protobuf/stubs/atomicops.h> +#include <atomic> + #include <google/protobuf/stubs/mutex.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/generated_message_reflection.h> @@ -86,6 +87,8 @@ class LIBPROTOBUF_EXPORT MapFieldBase { virtual bool ContainsMapKey(const MapKey& map_key) const = 0; virtual bool InsertOrLookupMapValue( const MapKey& map_key, MapValueRef* val) = 0; + // Returns whether changes to the map are reflected in the repeated field. + bool IsRepeatedFieldValid() const; // Insures operations after won't get executed before calling this. bool IsMapValid() const; virtual bool DeleteMapValue(const MapKey& map_key) = 0; @@ -140,9 +143,7 @@ class LIBPROTOBUF_EXPORT MapFieldBase { mutable Mutex mutex_; // The thread to synchronize map and repeated field // needs to get lock first; - mutable volatile Atomic32 state_; // 0: STATE_MODIFIED_MAP - // 1: STATE_MODIFIED_REPEATED - // 2: CLEAN + mutable std::atomic<State> state_; private: friend class ContendedMapCleanTest; @@ -180,10 +181,10 @@ class TypeDefinedMapFieldBase : public MapFieldBase { public: TypeDefinedMapFieldBase() {} explicit TypeDefinedMapFieldBase(Arena* arena) : MapFieldBase(arena) {} - ~TypeDefinedMapFieldBase() {} - void MapBegin(MapIterator* map_iter) const; - void MapEnd(MapIterator* map_iter) const; - bool EqualIterator(const MapIterator& a, const MapIterator& b) const; + ~TypeDefinedMapFieldBase() override {} + void MapBegin(MapIterator* map_iter) const override; + void MapEnd(MapIterator* map_iter) const override; + bool EqualIterator(const MapIterator& a, const MapIterator& b) const override; virtual const Map<Key, T>& GetMap() const = 0; virtual Map<Key, T>* MutableMap() = 0; @@ -193,11 +194,11 @@ class TypeDefinedMapFieldBase : public MapFieldBase { const MapIterator* map_iter) const; private: - void InitializeIterator(MapIterator* map_iter) const; - void DeleteIterator(MapIterator* map_iter) const; + void InitializeIterator(MapIterator* map_iter) const override; + void DeleteIterator(MapIterator* map_iter) const override; void CopyIterator(MapIterator* this_iteratorm, - const MapIterator& that_iterator) const; - void IncreaseIterator(MapIterator* map_iter) const; + const MapIterator& that_iterator) const override; + void IncreaseIterator(MapIterator* map_iter) const override; virtual void SetMapIteratorValue(MapIterator* map_iter) const = 0; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeDefinedMapFieldBase); @@ -242,16 +243,16 @@ class MapField : public TypeDefinedMapFieldBase<Key, T> { : TypeDefinedMapFieldBase<Key, T>(arena), impl_(arena) {} // Implement MapFieldBase - bool ContainsMapKey(const MapKey& map_key) const; - bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val); - bool DeleteMapValue(const MapKey& map_key); + bool ContainsMapKey(const MapKey& map_key) const override; + bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val) override; + bool DeleteMapValue(const MapKey& map_key) override; - const Map<Key, T>& GetMap() const { + const Map<Key, T>& GetMap() const override { MapFieldBase::SyncMapWithRepeatedField(); return impl_.GetMap(); } - Map<Key, T>* MutableMap() { + Map<Key, T>* MutableMap() override { MapFieldBase::SyncMapWithRepeatedField(); Map<Key, T>* result = impl_.MutableMap(); MapFieldBase::SetMapDirty(); @@ -259,7 +260,7 @@ class MapField : public TypeDefinedMapFieldBase<Key, T> { } // Convenient methods for generated message implementation. - int size() const; + int size() const override; void Clear(); void MergeFrom(const MapField& other); void Swap(MapField* other); @@ -284,12 +285,13 @@ class MapField : public TypeDefinedMapFieldBase<Key, T> { typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; + // Implements MapFieldBase - void SyncRepeatedFieldWithMapNoLock() const; - void SyncMapWithRepeatedFieldNoLock() const; - size_t SpaceUsedExcludingSelfNoLock() const; + void SyncRepeatedFieldWithMapNoLock() const override; + void SyncMapWithRepeatedFieldNoLock() const override; + size_t SpaceUsedExcludingSelfNoLock() const override; - void SetMapIteratorValue(MapIterator* map_iter) const; + void SetMapIteratorValue(MapIterator* map_iter) const override; friend class ::google::protobuf::Arena; friend class MapFieldStateTest; // For testing, it needs raw access to impl_ @@ -310,27 +312,27 @@ class LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase<MapKey, public: explicit DynamicMapField(const Message* default_entry); DynamicMapField(const Message* default_entry, Arena* arena); - ~DynamicMapField(); + ~DynamicMapField() override; // Implement MapFieldBase - bool ContainsMapKey(const MapKey& map_key) const; - bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val); - bool DeleteMapValue(const MapKey& map_key); + bool ContainsMapKey(const MapKey& map_key) const override; + bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val) override; + bool DeleteMapValue(const MapKey& map_key) override; - const Map<MapKey, MapValueRef>& GetMap() const; - Map<MapKey, MapValueRef>* MutableMap(); + const Map<MapKey, MapValueRef>& GetMap() const override; + Map<MapKey, MapValueRef>* MutableMap() override; - int size() const; + int size() const override; private: Map<MapKey, MapValueRef> map_; const Message* default_entry_; // Implements MapFieldBase - void SyncRepeatedFieldWithMapNoLock() const; - void SyncMapWithRepeatedFieldNoLock() const; - size_t SpaceUsedExcludingSelfNoLock() const; - void SetMapIteratorValue(MapIterator* map_iter) const; + void SyncRepeatedFieldWithMapNoLock() const override; + void SyncMapWithRepeatedFieldNoLock() const override; + size_t SpaceUsedExcludingSelfNoLock() const override; + void SetMapIteratorValue(MapIterator* map_iter) const override; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMapField); }; @@ -814,13 +816,13 @@ struct hash<google::protobuf::MapKey> { case google::protobuf::FieldDescriptor::CPPTYPE_STRING: return hash<string>()(map_key.GetStringValue()); case google::protobuf::FieldDescriptor::CPPTYPE_INT64: - return hash< ::google::protobuf::int64>()(map_key.GetInt64Value()); + return hash<::google::protobuf::int64>()(map_key.GetInt64Value()); case google::protobuf::FieldDescriptor::CPPTYPE_INT32: - return hash< ::google::protobuf::int32>()(map_key.GetInt32Value()); + return hash<::google::protobuf::int32>()(map_key.GetInt32Value()); case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: - return hash< ::google::protobuf::uint64>()(map_key.GetUInt64Value()); + return hash<::google::protobuf::uint64>()(map_key.GetUInt64Value()); case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: - return hash< ::google::protobuf::uint32>()(map_key.GetUInt32Value()); + return hash<::google::protobuf::uint32>()(map_key.GetUInt32Value()); case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: return hash<bool>()(map_key.GetBoolValue()); } |