summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <tegge@oath.com>2017-08-18 13:34:25 +0000
committerTor Egge <tegge@oath.com>2017-08-18 13:43:53 +0000
commit3cd6a5cc46d8fb48082b40e7a66eb62b49fe6c63 (patch)
tree4b9b543c27ff7ef4ebf041fc7b1e2593f896b720 /searchcore
parenteac90beb5009dbc7c4ae0084f0e78e1d8d2a5fa8 (diff)
Add ImportedAttributeVectorReadGuard, used to handle imported attributes
via ImportedAttributesContext in a safe manner.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp21
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h15
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;