summaryrefslogtreecommitdiffstats
path: root/searchlib
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 /searchlib
parentf7bae8762a87c0b7020388e1332ed8c2ef1a6fef (diff)
Revert "Remove thread sanitizer lock order reversal warning for attribute context."
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributecontext.cpp29
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributecontext.h3
2 files changed, 15 insertions, 17 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp b/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp
index e9a9f83d5db..598fdc7ac40 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp
@@ -12,24 +12,21 @@ namespace search {
const IAttributeVector *
AttributeContext::getAttribute(AttributeMap & map, const string & name, bool stableEnum) const
{
- std::unique_lock guard(_cacheLock);
AttributeMap::const_iterator itr = map.find(name);
- std::shared_future<std::unique_ptr<attribute::AttributeReadGuard>> future_read_guard;
if (itr != map.end()) {
- future_read_guard = itr->second;
- guard.unlock();
+ if (itr->second) {
+ return itr->second->attribute();
+ } else {
+ return nullptr;
+ }
} else {
- std::promise<std::unique_ptr<attribute::AttributeReadGuard>> promise;
- future_read_guard = promise.get_future().share();
- map[name] = future_read_guard;
- guard.unlock();
- promise.set_value(_manager.getAttributeReadGuard(name, stableEnum));
- }
- auto& read_guard = future_read_guard.get();
- if (read_guard) {
- return read_guard->attribute();
- } else {
- return nullptr;
+ auto readGuard = _manager.getAttributeReadGuard(name, stableEnum);
+ const IAttributeVector *attribute = nullptr;
+ if (readGuard) {
+ attribute = readGuard->attribute();
+ }
+ map[name] = std::move(readGuard);
+ return attribute;
}
}
@@ -45,12 +42,14 @@ AttributeContext::~AttributeContext() = default;
const IAttributeVector *
AttributeContext::getAttribute(const string & name) const
{
+ std::lock_guard<std::mutex> guard(_cacheLock);
return getAttribute(_attributes, name, false);
}
const IAttributeVector *
AttributeContext::getAttributeStableEnum(const string & name) const
{
+ std::lock_guard<std::mutex> guard(_cacheLock);
return getAttribute(_enumAttributes, name, true);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/attributecontext.h b/searchlib/src/vespa/searchlib/attribute/attributecontext.h
index 08516009914..4ba3d07ef74 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributecontext.h
+++ b/searchlib/src/vespa/searchlib/attribute/attributecontext.h
@@ -5,7 +5,6 @@
#include <vespa/searchcommon/attribute/iattributecontext.h>
#include <vespa/vespalib/stllike/hash_map.h>
#include "iattributemanager.h"
-#include <future>
#include <mutex>
namespace search {
@@ -17,7 +16,7 @@ namespace search {
class AttributeContext : public attribute::IAttributeContext
{
private:
- using AttributeMap = vespalib::hash_map<string, std::shared_future<std::unique_ptr<attribute::AttributeReadGuard>>>;
+ using AttributeMap = vespalib::hash_map<string, std::unique_ptr<attribute::AttributeReadGuard>>;
using IAttributeVector = attribute::IAttributeVector;
using IAttributeFunctor = attribute::IAttributeFunctor;