diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2023-02-20 14:01:19 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2023-02-20 14:45:45 +0000 |
commit | b5938e1a0c6edcb156b9db7ec460764cfa61aeab (patch) | |
tree | 6556ffb000cd9227a90cbe151c52d31d0a53a826 | |
parent | 50456d18a169ba8f3497568903d7721687643367 (diff) |
remove search::Runnable
5 files changed, 45 insertions, 82 deletions
diff --git a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp index 0b90b4eae95..d5ea6fdaffc 100644 --- a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp +++ b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp @@ -5,7 +5,7 @@ #include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchcommon/attribute/config.h> -#include <vespa/fastos/thread.h> +#include <thread> #include <vespa/vespalib/util/signalhandler.h> #include <iostream> #include "attributesearcher.h" @@ -96,7 +96,6 @@ private: static struct rusage computeDifference(struct rusage & first, struct rusage & second); }; - FastOS_ThreadPool * _threadPool; Config _config; RandomGenerator _rndGen; @@ -129,12 +128,8 @@ private: public: - AttributeBenchmark() : _threadPool(NULL), _config(), _rndGen() {} - ~AttributeBenchmark() { - if (_threadPool != NULL) { - delete _threadPool; - } - } + AttributeBenchmark() : _config(), _rndGen() {} + ~AttributeBenchmark() = default; int main(int argc, char **argv); }; @@ -268,7 +263,7 @@ AttributeBenchmark::benchmarkSearch(const AttributePtr & ptr, const std::vector< } else { searchers.push_back(new AttributeFindSearcher<T>(ptr, values, _config._numQueries)); } - _threadPool->NewThread(searchers.back()); + searchers.back()->start(); } for (uint32_t i = 0; i < searchers.size(); ++i) { @@ -299,7 +294,7 @@ AttributeBenchmark::benchmarkSearchWithUpdater(const AttributePtr & ptr, AttributeUpdaterThread<Vector, T, BT> updater(ptr, values, _rndGen, _config._validate, _config._commitFreq, _config._minValueCount, _config._maxValueCount); - _threadPool->NewThread(&updater); + updater.start(); benchmarkSearch(ptr, values); updater.stop(); updater.join(); @@ -337,8 +332,6 @@ AttributeBenchmark::benchmarkAttribute(const AttributePtr & ptr, const std::vect } else { benchmarkSearchWithUpdater<Vector, T, BT>(ptr, values); } - - _threadPool->Close(); } @@ -569,8 +562,6 @@ AttributeBenchmark::main(int argc, char **argv) dc._attribute = vespalib::string(argv[optind]); - _threadPool = new FastOS_ThreadPool(); - std::cout << "<attribute-benchmark>" << std::endl; init(dc); _config.printXML(); diff --git a/searchlib/src/tests/attribute/benchmark/attributesearcher.h b/searchlib/src/tests/attribute/benchmark/attributesearcher.h index d6e14d6793d..ea2d7190f25 100644 --- a/searchlib/src/tests/attribute/benchmark/attributesearcher.h +++ b/searchlib/src/tests/attribute/benchmark/attributesearcher.h @@ -2,7 +2,6 @@ #pragma once -#include <vespa/searchlib/util/runnable.h> #include <vespa/searchlib/attribute/attribute.h> #include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/attribute/search_context.h> @@ -59,7 +58,7 @@ public: }; -class AttributeSearcher : public Runnable +class AttributeSearcher { protected: using AttributePtr = AttributeVector::SP; @@ -67,17 +66,23 @@ protected: const AttributePtr & _attrPtr; vespalib::Timer _timer; AttributeSearcherStatus _status; - + std::thread _thread; + public: - AttributeSearcher(const AttributePtr & attrPtr) : - Runnable(), _attrPtr(attrPtr), _timer(), _status() + AttributeSearcher(const AttributePtr & attrPtr) + : _attrPtr(attrPtr), _timer(), _status(), _thread() { _status._numClients = 1; } - virtual void doRun() override = 0; + virtual ~AttributeSearcher(); + virtual void doRun() = 0; + void start() { _thread = std::thread([this](){doRun();}); } + void join() { _thread.join(); } AttributeSearcherStatus & getStatus() { return _status; } void buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const char * term, bool prefix = false); }; +AttributeSearcher::~AttributeSearcher() = default; + void AttributeSearcher::buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const char * term, bool prefix) diff --git a/searchlib/src/tests/attribute/benchmark/attributeupdater.h b/searchlib/src/tests/attribute/benchmark/attributeupdater.h index 88220a8cfb8..ada9c423cd1 100644 --- a/searchlib/src/tests/attribute/benchmark/attributeupdater.h +++ b/searchlib/src/tests/attribute/benchmark/attributeupdater.h @@ -4,7 +4,6 @@ #include <vespa/vespalib/util/hdr_abort.h> #include <vespa/searchlib/util/randomgenerator.h> -#include <vespa/searchlib/util/runnable.h> #include <vespa/searchlib/attribute/attribute.h> #define VALIDATOR_STR(str) #str @@ -153,26 +152,30 @@ template <typename Vector, typename T, typename BT> AttributeUpdater<Vector, T, BT>::~AttributeUpdater() = default; template <typename Vector, typename T, typename BT> -class AttributeUpdaterThread : public AttributeUpdater<Vector, T, BT>, public Runnable +class AttributeUpdaterThread : public AttributeUpdater<Vector, T, BT> { private: using AttributePtr = AttributeVector::SP; - + std::atomic<bool> _done; + std::thread _thread; public: AttributeUpdaterThread(const AttributePtr & attrPtr, const std::vector<T> & values, RandomGenerator & rndGen, bool validate, uint32_t commitFreq, uint32_t minValueCount, uint32_t maxValueCount); ~AttributeUpdaterThread(); - - virtual void doRun() override; + void doRun(); + void start() { _thread = std::thread([this](){doRun();}); } + void stop() { _done = true; } + void join() { _thread.join(); } }; template <typename Vector, typename T, typename BT> AttributeUpdaterThread<Vector, T, BT>::AttributeUpdaterThread(const AttributePtr & attrPtr, const std::vector<T> & values, RandomGenerator & rndGen, bool validate, uint32_t commitFreq, uint32_t minValueCount, uint32_t maxValueCount) - : AttributeUpdater<Vector, T, BT>(attrPtr, values, rndGen, validate, commitFreq, minValueCount, maxValueCount), - Runnable() + : AttributeUpdater<Vector, T, BT>(attrPtr, values, rndGen, validate, commitFreq, minValueCount, maxValueCount), + _done(false), + _thread() {} template <typename Vector, typename T, typename BT> AttributeUpdaterThread<Vector, T, BT>::~AttributeUpdaterThread() = default; diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp index eb457f312e6..f0ca11a2cc8 100644 --- a/searchlib/src/tests/transactionlogstress/translogstress.cpp +++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp @@ -5,7 +5,6 @@ #include <vespa/searchlib/transactionlog/translogclient.h> #include <vespa/vespalib/util/rand48.h> #include <vespa/vespalib/util/size_literals.h> -#include <vespa/searchlib/util/runnable.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/fnet/transport.h> #include <vespa/vespalib/util/signalhandler.h> @@ -13,6 +12,7 @@ #include <sstream> #include <thread> #include <unistd.h> +#include <vespa/fastos/thread.h> #include <vespa/log/log.h> #include <vespa/vespalib/util/time.h> @@ -20,7 +20,6 @@ LOG_SETUP("translogstress"); using vespalib::nbostream; -using search::Runnable; using std::shared_ptr; using vespalib::make_string; using vespalib::ConstBufferRef; @@ -190,7 +189,7 @@ public: //----------------------------------------------------------------------------- // FeederThread //----------------------------------------------------------------------------- -class FeederThread : public Runnable +class FeederThread { private: std::string _tlsSpec; @@ -203,6 +202,8 @@ private: SerialNum _current; SerialNum _lastCommited; vespalib::Timer _timer; + std::atomic<bool> _done; + std::thread _thread; void commitPacket(); bool addEntry(const Packet::Entry & e); @@ -210,8 +211,11 @@ private: public: FeederThread(FNET_Transport & transport, const std::string & tlsSpec, const std::string & domain, const EntryGenerator & generator, uint32_t feedRate, size_t packetSize); - ~FeederThread() override; - void doRun() override; + ~FeederThread(); + void doRun(); + void start() { _thread = std::thread([this](){doRun();}); } + void stop() { _done = true; } + void join() { _thread.join(); } SerialNumRange getRange() const { return SerialNumRange(1, _lastCommited); } }; @@ -450,7 +454,7 @@ VisitorAgent::receive(const Packet & packet) //----------------------------------------------------------------------------- // ControllerThread //----------------------------------------------------------------------------- -class ControllerThread : public Runnable +class ControllerThread { private: std::string _tlsSpec; @@ -466,7 +470,9 @@ private: SerialNum _begin; SerialNum _end; size_t _count; - + std::atomic<bool> _done; + std::thread _thread; + void getStatus(); void makeRandomVisitorVector(); @@ -475,8 +481,10 @@ public: uint32_t numVisitors, vespalib::duration visitorInterval, vespalib::duration pruneInterval); ~ControllerThread(); std::vector<std::shared_ptr<VisitorAgent> > & getVisitors() { return _visitors; } - virtual void doRun() override; - + void doRun(); + void start() { _thread = std::thread([this](){doRun();}); } + void stop() { _done = true; } + void join() { _thread.join(); } }; ControllerThread::ControllerThread(FNET_Transport & transport, const std::string & tlsSpec, const std::string & domain, @@ -719,12 +727,12 @@ TransLogStress::main(int argc, char **argv) // start feeder and controller FeederThread feeder(transport, tlsSpec, domain, generator, _cfg.feedRate, _cfg.packetSize); - threadPool.NewThread(&feeder); + feeder.start(); std::this_thread::sleep_for(sleepTime); ControllerThread controller(transport, tlsSpec, domain, generator, _cfg.numVisitors, _cfg.visitorInterval, _cfg.pruneInterval); - threadPool.NewThread(&controller); + controller.start(); // stop feeder and controller std::this_thread::sleep_for(_cfg.stressTime); diff --git a/searchlib/src/vespa/searchlib/util/runnable.h b/searchlib/src/vespa/searchlib/util/runnable.h deleted file mode 100644 index 4b353209762..00000000000 --- a/searchlib/src/vespa/searchlib/util/runnable.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include <mutex> -#include <condition_variable> -#include <vespa/fastos/thread.h> - -namespace search { - -class Runnable : public FastOS_Runnable -{ -protected: - std::mutex _lock; - std::condition_variable _cond; - bool _done; - bool _stopped; - -public: - Runnable() : - _lock(), _cond(), _done(false), _stopped(false) - { } - void Run(FastOS_ThreadInterface *, void *) override { - doRun(); - - std::lock_guard<std::mutex> guard(_lock); - _stopped = true; - _cond.notify_all(); - } - virtual void doRun() = 0; - void stop() { - std::lock_guard<std::mutex> guard(_lock); - _done = true; - } - void join() { - std::unique_lock<std::mutex> guard(_lock); - while (!_stopped) { - _cond.wait(guard); - } - } -}; - -} // search - |