summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2017-11-14 15:02:26 +0100
committerTor Egge <Tor.Egge@broadpark.no>2017-11-14 15:02:26 +0100
commitd6139a1b8bdda3ccc343c994cd5604a56e9f454d (patch)
treead50b529db512f1d3610fe8174ba9bfefe872d6f /searchcore
parent75292c03131519ec0eeea2d9f09594e93508c91e (diff)
Use std::lock_guard and scopes instead of std::unique_lock.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp b/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp
index 4bc5071b523..6f2fbabfb1c 100644
--- a/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp
+++ b/searchcore/src/vespa/searchcore/proton/persistenceengine/persistenceengine.cpp
@@ -460,28 +460,31 @@ PersistenceEngine::IterateResult
PersistenceEngine::iterate(IteratorId id, uint64_t maxByteSize, Context&) const
{
std::shared_lock<std::shared_timed_mutex> rguard(_rwMutex);
- std::unique_lock<std::mutex> guard(_iterators_lock);
- auto it = _iterators.find(id);
- if (it == _iterators.end()) {
- return IterateResult(Result::PERMANENT_ERROR, make_string("Unknown iterator with id %" PRIu64, id.getValue()));
- }
- if (it->second->in_use) {
- return IterateResult(Result::TRANSIENT_ERROR, make_string("Iterator with id %" PRIu64 " is already in use", id.getValue()));
+ IteratorEntry *iteratorEntry;
+ {
+ std::lock_guard<std::mutex> guard(_iterators_lock);
+ auto it = _iterators.find(id);
+ if (it == _iterators.end()) {
+ return IterateResult(Result::PERMANENT_ERROR, make_string("Unknown iterator with id %" PRIu64, id.getValue()));
+ }
+ iteratorEntry = it->second;
+ if (iteratorEntry->in_use) {
+ return IterateResult(Result::TRANSIENT_ERROR, make_string("Iterator with id %" PRIu64 " is already in use", id.getValue()));
+ }
+ iteratorEntry->in_use = true;
}
- it->second->in_use = true;
- guard.unlock();
- DocumentIterator &iterator = it->second->it;
+ DocumentIterator &iterator = iteratorEntry->it;
try {
IterateResult result = iterator.iterate(maxByteSize);
- guard.lock();
- it->second->in_use = false;
+ std::lock_guard<std::mutex> guard(_iterators_lock);
+ iteratorEntry->in_use = false;
return result;
} catch (const std::exception & e) {
IterateResult result(Result::PERMANENT_ERROR, make_string("Caught exception during visitor iterator.iterate() = '%s'", e.what()));
LOG(warning, "Caught exception during visitor iterator.iterate() = '%s'", e.what());
- guard.lock();
- it->second->in_use = false;
+ std::lock_guard<std::mutex> guard(_iterators_lock);
+ iteratorEntry->in_use = false;
return result;
}
}