diff options
author | Geir Storli <geirstorli@yahoo.no> | 2017-08-21 11:06:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-21 11:06:44 +0200 |
commit | 9daff68e0cfd4e88e43bfafb3b5085b4e9e0de0f (patch) | |
tree | d40b618ae04b8479019c381509cae1df94b219a3 /searchcore | |
parent | 3a78992a83949fd4d085badc6f2dc241afb5560b (diff) | |
parent | 3cd6a5cc46d8fb48082b40e7a66eb62b49fe6c63 (diff) |
Merge pull request #3158 from vespa-engine/toregge/add-imported-attribute-vector-read-guard
Add ImportedAttributeVectorReadGuard, used to handle imported attributes
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp | 21 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h | 15 |
2 files changed, 3 insertions, 33 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp index 306030dbe3e..7a9d877621c 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp @@ -12,23 +12,6 @@ using LockGuard = std::lock_guard<std::mutex>; namespace proton { -ImportedAttributesContext::GuardedAttribute::GuardedAttribute(ImportedAttributeVector::SP attr, - bool stableEnumGuard) - : _attr(std::move(attr)), - _guard(stableEnumGuard ? _attr->acquireEnumGuard() : _attr->acquireGuard()) -{ -} - -ImportedAttributesContext::GuardedAttribute::~GuardedAttribute() -{ -} - -const IAttributeVector * -ImportedAttributesContext::GuardedAttribute::get() const -{ - return _attr.get(); -} - const IAttributeVector * ImportedAttributesContext::getOrCacheAttribute(const vespalib::string &name, AttributeCache &attributes, @@ -41,8 +24,8 @@ ImportedAttributesContext::getOrCacheAttribute(const vespalib::string &name, } ImportedAttributeVector::SP result = _repo.get(name); if (result.get() != nullptr) { - attributes.emplace(name, GuardedAttribute(result, stableEnumGuard)); - return result.get(); + auto insRes = attributes.emplace(name, result->makeReadGuard(stableEnumGuard)); + return insRes.first->second.get(); } else { return nullptr; } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h index c8c9d021a5f..5daed203446 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h @@ -29,20 +29,7 @@ private: using IAttributeVector = search::attribute::IAttributeVector; using ImportedAttributeVector = search::attribute::ImportedAttributeVector; - class GuardedAttribute { - private: - std::shared_ptr<ImportedAttributeVector> _attr; - std::unique_ptr<AttributeGuard> _guard; - - public: - GuardedAttribute(std::shared_ptr<ImportedAttributeVector> attr, bool stableEnumGuard); - ~GuardedAttribute(); - GuardedAttribute(GuardedAttribute &&rhs) = default; - GuardedAttribute &operator=(GuardedAttribute &&rhs) = default; - const IAttributeVector *get() const; - }; - - using AttributeCache = std::unordered_map<vespalib::string, GuardedAttribute, vespalib::hash<vespalib::string>>; + using AttributeCache = std::unordered_map<vespalib::string, std::unique_ptr<ImportedAttributeVector>, vespalib::hash<vespalib::string>>; using LockGuard = std::lock_guard<std::mutex>; const ImportedAttributesRepo &_repo; |