diff options
author | Tor Egge <Tor.Egge@oath.com> | 2017-12-12 13:01:15 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-12-12 13:01:15 +0000 |
commit | 9408c19cd6d340d9d2f09c67699e67afd62fbb12 (patch) | |
tree | 48e3f148b55281a96a718c52db458fbbbc50e528 | |
parent | ad70d622d76fd6a59272b16da1a3787d5f85c193 (diff) |
Use standard locking in searchlib (pass 1).
12 files changed, 46 insertions, 43 deletions
diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp index 2de13545beb..bf88a0c3003 100644 --- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp +++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp @@ -34,6 +34,7 @@ #include <vespa/vespalib/util/closuretask.h> #include <vespa/vespalib/util/gate.h> #include <vespa/vespalib/util/threadstackexecutor.h> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP("maintenancecontroller_test"); diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp index 3d3231a5e09..c8b2e81a9c0 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp @@ -7,6 +7,7 @@ #include <vespa/fastlib/io/bufferedfile.h> #include <vespa/vespalib/util/exceptions.h> #include <sstream> +#include <unistd.h> #include <vespa/log/log.h> LOG_SETUP(".searchcorespi.index.indexwriteutilities"); diff --git a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp index cd0a4caf33b..75412dcf8e9 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp @@ -117,7 +117,7 @@ WarmupIndexCollection::fireWarmup(Task::UP task) if (now < _warmupEndTime) { _executor.execute(std::move(task)); } else { - vespalib::LockGuard guard(_lock); + std::unique_lock<std::mutex> guard(_lock); if (_warmupEndTime != 0) { _warmupEndTime = 0; guard.unlock(); @@ -133,7 +133,7 @@ WarmupIndexCollection::handledBefore(uint32_t fieldId, const Node &term) const StringBase * sb(dynamic_cast<const StringBase *>(&term)); if (sb != NULL) { const vespalib::string & s = sb->getTerm(); - vespalib::LockGuard guard(_lock); + std::lock_guard<std::mutex> guard(_lock); TermMap::insert_result found = (*_handledTerms)[fieldId].insert(s); return ! found.second; } diff --git a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h index 96f46610a29..f6d6bc89fc4 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h +++ b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h @@ -99,7 +99,7 @@ private: vespalib::ThreadExecutor & _executor; IWarmupDone & _warmupDone; fastos::TimeStamp _warmupEndTime; - vespalib::Lock _lock; + std::mutex _lock; std::unique_ptr<FieldTermMap> _handledTerms; }; diff --git a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp index 8eef498d85c..e2dc6b2b2ef 100644 --- a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp +++ b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp @@ -21,8 +21,6 @@ LOG_SETUP("attributebenchmark"); #include <vespa/searchlib/attribute/attributevector.hpp> -using vespalib::Monitor; -using vespalib::MonitorGuard; using std::shared_ptr; typedef std::vector<uint32_t> NumVector; diff --git a/searchlib/src/tests/attribute/runnable.h b/searchlib/src/tests/attribute/runnable.h index b95d7d3843f..fb0a7cb1825 100644 --- a/searchlib/src/tests/attribute/runnable.h +++ b/searchlib/src/tests/attribute/runnable.h @@ -2,7 +2,8 @@ #pragma once -#include <vespa/vespalib/util/sync.h> +#include <mutex> +#include <condition_variable> #include <vespa/fastos/thread.h> namespace search { @@ -10,31 +11,32 @@ namespace search { class Runnable : public FastOS_Runnable { protected: - uint32_t _id; - vespalib::Monitor _cond; - bool _done; - bool _stopped; + uint32_t _id; + std::mutex _lock; + std::condition_variable _cond; + bool _done; + bool _stopped; public: Runnable(uint32_t id) : - _id(id), _cond(), _done(false), _stopped(false) + _id(id), _lock(), _cond(), _done(false), _stopped(false) { } void Run(FastOS_ThreadInterface *, void *) override { doRun(); - vespalib::MonitorGuard guard(_cond); + std::lock_guard<std::mutex> guard(_lock); _stopped = true; - guard.broadcast(); + _cond.notify_all(); } virtual void doRun() = 0; void stop() { - vespalib::MonitorGuard guard(_cond); + std::lock_guard<std::mutex> guard(_lock); _done = true; } void join() { - vespalib::MonitorGuard guard(_cond); + std::unique_lock<std::mutex> guard(_lock); while (!_stopped) { - guard.wait(); + _cond.wait(guard); } } }; diff --git a/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp b/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp index 770d5c653a3..0a3fe963aae 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributecontext.cpp @@ -43,19 +43,19 @@ AttributeContext::~AttributeContext() { } const IAttributeVector * AttributeContext::getAttribute(const string & name) const { - vespalib::LockGuard guard(_cacheLock); + std::lock_guard<std::mutex> guard(_cacheLock); return getAttribute(_attributes, name, false); } const IAttributeVector * AttributeContext::getAttributeStableEnum(const string & name) const { - vespalib::LockGuard guard(_cacheLock); + std::lock_guard<std::mutex> guard(_cacheLock); return getAttribute(_enumAttributes, name, true); } void AttributeContext::releaseEnumGuards() { - vespalib::LockGuard guard(_cacheLock); + std::lock_guard<std::mutex> guard(_cacheLock); _enumAttributes.clear(); } diff --git a/searchlib/src/vespa/searchlib/attribute/attributecontext.h b/searchlib/src/vespa/searchlib/attribute/attributecontext.h index b7373f343ec..80abe84f8ef 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributecontext.h +++ b/searchlib/src/vespa/searchlib/attribute/attributecontext.h @@ -3,9 +3,9 @@ #pragma once #include <vespa/searchcommon/attribute/iattributecontext.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/stllike/hash_map.h> #include "iattributemanager.h" +#include <mutex> namespace search { @@ -21,7 +21,7 @@ private: const search::IAttributeManager & _manager; mutable AttributeMap _attributes; mutable AttributeMap _enumAttributes; - mutable vespalib::Lock _cacheLock; + mutable std::mutex _cacheLock; const attribute::IAttributeVector * getAttribute(AttributeMap & map, const string & name, bool stableEnum) const; diff --git a/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp b/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp index 0122516b767..f10f3491ac0 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributemanager.cpp @@ -12,14 +12,14 @@ #include <vespa/log/log.h> LOG_SETUP(".searchlib.attributemanager"); -using vespalib::LockGuard; using vespalib::string; using vespalib::IllegalStateException; using search::attribute::IAttributeContext; namespace { -vespalib::Monitor baseDirMonitor; +std::mutex baseDirLock; +std::condition_variable baseDirCond; typedef std::set<string> BaseDirSet; BaseDirSet baseDirSet; @@ -27,7 +27,7 @@ static void waitBaseDir(const string &baseDir) { if (baseDir.empty()) { return; } - vespalib::MonitorGuard guard(baseDirMonitor); + std::unique_lock<std::mutex> guard(baseDirLock); bool waited = false; BaseDirSet::iterator it = baseDirSet.find(baseDir); @@ -36,7 +36,7 @@ waitBaseDir(const string &baseDir) waited = true; LOG(debug, "AttributeManager: Waiting for basedir %s to be available", baseDir.c_str()); } - guard.wait(); + baseDirCond.wait(guard); it = baseDirSet.find(baseDir); } @@ -52,7 +52,7 @@ dropBaseDir(const string &baseDir) { if (baseDir.empty()) return; - vespalib::MonitorGuard guard(baseDirMonitor); + std::lock_guard<std::mutex> guard(baseDirLock); BaseDirSet::iterator it = baseDirSet.find(baseDir); if (it == baseDirSet.end()) { @@ -60,7 +60,7 @@ dropBaseDir(const string &baseDir) } else { baseDirSet.erase(it); } - guard.broadcast(); + baseDirCond.notify_all(); } } @@ -147,7 +147,7 @@ AttributeManager::findAndLoadAttribute(const string & name) const if (found != _attributes.end()) { AttributeVector & vec = *found->second; if ( ! vec.isLoaded() ) { - vespalib::LockGuard loadGuard(_loadLock); + std::lock_guard<std::mutex> loadGuard(_loadLock); if ( ! vec.isLoaded() ) { vec.load(); } else { diff --git a/searchlib/src/vespa/searchlib/attribute/attributemanager.h b/searchlib/src/vespa/searchlib/attribute/attributemanager.h index f69d4cb9295..3b23881e3bc 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributemanager.h +++ b/searchlib/src/vespa/searchlib/attribute/attributemanager.h @@ -7,7 +7,7 @@ #include <vespa/searchlib/common/indexmetainfo.h> #include <vespa/searchcommon/attribute/config.h> #include <vespa/vespalib/stllike/hash_map.h> -#include <vespa/vespalib/util/sync.h> +#include <mutex> namespace search { @@ -56,7 +56,7 @@ public: protected: typedef vespalib::hash_map<string, VectorHolder> AttributeMap; AttributeMap _attributes; - vespalib::Lock _loadLock; + mutable std::mutex _loadLock; private: const VectorHolder * findAndLoadAttribute(const string & name) const; string createBaseFileName(const string & name, bool useSnapshot) const; diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h index 13ba3f801b7..b514a5830ba 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.h +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h @@ -19,8 +19,7 @@ #include <vespa/searchlib/queryeval/searchiterator.h> #include <vespa/vespalib/objects/identifiable.h> #include <vespa/vespalib/stllike/asciistream.h> -#include <vespa/vespalib/util/rwlock.h> -#include <vespa/vespalib/util/sync.h> +#include <vespa/fastos/time.h> #include <cmath> #include <mutex> #include <shared_mutex> diff --git a/searchlib/src/vespa/searchlib/util/runnable.h b/searchlib/src/vespa/searchlib/util/runnable.h index a8dc8e56856..a95d4d68368 100644 --- a/searchlib/src/vespa/searchlib/util/runnable.h +++ b/searchlib/src/vespa/searchlib/util/runnable.h @@ -2,37 +2,39 @@ #pragma once -#include <vespa/vespalib/util/sync.h> +#include <mutex> +#include <condition_variable> namespace search { class Runnable : public FastOS_Runnable { protected: - vespalib::Monitor _cond; - bool _done; - bool _stopped; + std::mutex _lock; + std::condition_variable _cond; + bool _done; + bool _stopped; public: Runnable() : - _cond(), _done(false), _stopped(false) + _lock(), _cond(), _done(false), _stopped(false) { } - void Run(FastOS_ThreadInterface *, void *) override{ + void Run(FastOS_ThreadInterface *, void *) override { doRun(); - vespalib::MonitorGuard guard(_cond); + std::lock_guard<std::mutex> guard(_lock); _stopped = true; - guard.broadcast(); + _cond.notify_all(); } virtual void doRun() = 0; void stop() { - vespalib::MonitorGuard guard(_cond); + std::lock_guard<std::mutex> guard(_lock); _done = true; } void join() { - vespalib::MonitorGuard guard(_cond); + std::unique_lock<std::mutex> guard(_lock); while (!_stopped) { - guard.wait(); + _cond.wait(guard); } } }; |