summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-03-04 16:03:48 +0100
committerGitHub <noreply@github.com>2022-03-04 16:03:48 +0100
commit08f69545e74c131692dbbffc63add6812ee75180 (patch)
treeb822dcbdcd476beb3717de28489d6d41ea29b4e7 /searchcore
parentf7bae8762a87c0b7020388e1332ed8c2ef1a6fef (diff)
Revert "Remove thread sanitizer lock order reversal warning for attribute context."
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp34
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h6
2 files changed, 15 insertions, 25 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 7a86a4c5f31..0069a61b818 100644
--- a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp
+++ b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.cpp
@@ -9,34 +9,22 @@
using search::attribute::IAttributeVector;
using search::attribute::ImportedAttributeVector;
+using LockGuard = std::lock_guard<std::mutex>;
namespace proton {
const IAttributeVector *
ImportedAttributesContext::getOrCacheAttribute(const vespalib::string &name, AttributeCache &attributes,
- bool stableEnumGuard) const
+ bool stableEnumGuard, const LockGuard &) const
{
- std::unique_lock guard(_cacheMutex);
- std::shared_future<std::unique_ptr<AttributeReadGuard>> future_read_guard;
auto itr = attributes.find(name);
if (itr != attributes.end()) {
- future_read_guard = itr->second;
- guard.unlock();
- } else {
- std::promise<std::unique_ptr<AttributeReadGuard>> promise;
- future_read_guard = promise.get_future().share();
- attributes.emplace(name, future_read_guard);
- guard.unlock();
- ImportedAttributeVector::SP result = _repo.get(name);
- if (result) {
- promise.set_value(result->makeReadGuard(stableEnumGuard));
- } else {
- promise.set_value(std::unique_ptr<AttributeReadGuard>());
- }
+ return itr->second->attribute();
}
- auto& read_guard = future_read_guard.get();
- if (read_guard) {
- return read_guard->attribute();
+ ImportedAttributeVector::SP result = _repo.get(name);
+ if (result) {
+ auto insRes = attributes.emplace(name, result->makeReadGuard(stableEnumGuard));
+ return insRes.first->second->attribute();
} else {
return nullptr;
}
@@ -55,13 +43,15 @@ ImportedAttributesContext::~ImportedAttributesContext() = default;
const IAttributeVector *
ImportedAttributesContext::getAttribute(const vespalib::string &name) const
{
- return getOrCacheAttribute(name, _guardedAttributes, false);
+ LockGuard guard(_cacheMutex);
+ return getOrCacheAttribute(name, _guardedAttributes, false, guard);
}
const IAttributeVector *
ImportedAttributesContext::getAttributeStableEnum(const vespalib::string &name) const
{
- return getOrCacheAttribute(name, _enumGuardedAttributes, true);
+ LockGuard guard(_cacheMutex);
+ return getOrCacheAttribute(name, _enumGuardedAttributes, true, guard);
}
void
@@ -77,7 +67,7 @@ ImportedAttributesContext::getAttributeList(std::vector<const IAttributeVector *
void
ImportedAttributesContext::releaseEnumGuards()
{
- std::lock_guard guard(_cacheMutex);
+ LockGuard guard(_cacheMutex);
_enumGuardedAttributes.clear();
}
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 33d6cef98ff..4b7058fdb83 100644
--- a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h
+++ b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h
@@ -4,7 +4,6 @@
#include <vespa/searchcommon/attribute/iattributecontext.h>
#include <vespa/vespalib/stllike/hash_fun.h>
#include <vespa/vespalib/stllike/hash_map.h>
-#include <future>
#include <mutex>
#include <unordered_map>
@@ -32,7 +31,8 @@ private:
using ImportedAttributeVector = search::attribute::ImportedAttributeVector;
using IAttributeFunctor = search::attribute::IAttributeFunctor;
- using AttributeCache = std::unordered_map<vespalib::string, std::shared_future<std::unique_ptr<AttributeReadGuard>>, vespalib::hash<vespalib::string>>;
+ using AttributeCache = std::unordered_map<vespalib::string, std::unique_ptr<AttributeReadGuard>, vespalib::hash<vespalib::string>>;
+ using LockGuard = std::lock_guard<std::mutex>;
const ImportedAttributesRepo &_repo;
mutable AttributeCache _guardedAttributes;
@@ -40,7 +40,7 @@ private:
mutable std::mutex _cacheMutex;
const IAttributeVector *getOrCacheAttribute(const vespalib::string &name, AttributeCache &attributes,
- bool stableEnumGuard) const;
+ bool stableEnumGuard, const LockGuard &) const;
public:
ImportedAttributesContext(const ImportedAttributesRepo &repo);