diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-23 15:42:51 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-23 21:33:55 +0000 |
commit | 494e4c6990f2224b53325a63205c660482a434ab (patch) | |
tree | b7aac02997643a3aaf8cc7ffd323da9e60b973f5 | |
parent | f184afbbbb011782776624f50eb5add144d5dbd2 (diff) |
Use lambda over closure. c++11ification
10 files changed, 87 insertions, 136 deletions
diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp index ab447d5d38f..637653ff428 100644 --- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp +++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp @@ -37,7 +37,7 @@ #include <vespa/searchlib/index/docbuilder.h> #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <vespa/vespalib/util/gate.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/fastos/thread.h> @@ -63,8 +63,7 @@ using search::SerialNum; using storage::spi::BucketInfo; using storage::spi::Timestamp; using vespalib::Slime; -using vespalib::makeClosure; -using vespalib::makeTask; +using vespalib::makeLambdaTask; using vespa::config::search::AttributesConfigBuilder; using storage::spi::dummy::DummyBucketExecutor; @@ -356,7 +355,6 @@ struct MockLidSpaceCompactionHandler : public ILidSpaceCompactionHandler void handleCompactLidSpace(const CompactLidSpaceOperation &, std::shared_ptr<IDestructorCallback>) override {} }; - class MaintenanceControllerFixture { public: @@ -388,7 +386,6 @@ public: MaintenanceController _mc; MaintenanceControllerFixture(); - ~MaintenanceControllerFixture(); void syncSubDBs(); @@ -481,10 +478,9 @@ public: void notifyBucketStateChanged(const document::BucketId &bucketId, BucketInfo::ActiveState newState) { - _executor.execute(makeTask(makeClosure(this, - &MaintenanceControllerFixture:: - performNotifyBucketStateChanged, - bucketId, newState))); + _executor.execute(makeLambdaTask([&]() { + performNotifyBucketStateChanged(bucketId, newState); + })); _executor.sync(); } }; @@ -744,19 +740,18 @@ MyFeedHandler::appendOperation(const FeedOperation &op, DoneCallback) const_cast<FeedOperation &>(op).setSerialNum(inc_serial_num()); } - MyExecutor::MyExecutor() : vespalib::ThreadStackExecutor(1, 128 * 1024), _threadId() { - execute(makeTask(makeClosure(&sampleThreadId, &_threadId))); + execute(makeLambdaTask([this]() { + sampleThreadId(&_threadId); + })); sync(); } - MyExecutor::~MyExecutor() = default; - bool MyExecutor::isIdle() { @@ -766,7 +761,6 @@ MyExecutor::isIdle() return stats.acceptedTasks == 0u; } - bool MyExecutor::waitIdle(vespalib::duration timeout) { @@ -814,47 +808,41 @@ MaintenanceControllerFixture::MaintenanceControllerFixture() syncSubDBs(); } - MaintenanceControllerFixture::~MaintenanceControllerFixture() { stopMaintenance(); } - void MaintenanceControllerFixture::syncSubDBs() { - _executor.execute(makeTask(makeClosure(this, &MaintenanceControllerFixture::performSyncSubDBs))); + _executor.execute(makeLambdaTask([this]() { performSyncSubDBs(); })); _executor.sync(); } - void MaintenanceControllerFixture::performSyncSubDBs() { _mc.syncSubDBs(_ready.getSubDB(), _removed.getSubDB(), _notReady.getSubDB()); } - void MaintenanceControllerFixture::notifyClusterStateChanged() { - _executor.execute(makeTask(makeClosure(this, &MaintenanceControllerFixture::performNotifyClusterStateChanged))); + _executor.execute(makeLambdaTask([this]() { performNotifyClusterStateChanged(); })); _executor.sync(); } - void MaintenanceControllerFixture::performNotifyClusterStateChanged() { _clusterStateHandler.notifyClusterStateChanged(_calc); } - void MaintenanceControllerFixture::startMaintenance() { - _executor.execute(makeTask(makeClosure(this, &MaintenanceControllerFixture::performStartMaintenance))); + _executor.execute(makeLambdaTask([this]() { performStartMaintenance(); })); _executor.sync(); } @@ -891,7 +879,7 @@ MaintenanceControllerFixture::stopMaintenance() void MaintenanceControllerFixture::forwardMaintenanceConfig() { - _executor.execute(makeTask(makeClosure(this, &MaintenanceControllerFixture::performForwardMaintenanceConfig))); + _executor.execute(makeLambdaTask([this]() { performForwardMaintenanceConfig(); })); _executor.sync(); } diff --git a/searchcore/src/tests/proton/metrics/job_tracked_flush/job_tracked_flush_test.cpp b/searchcore/src/tests/proton/metrics/job_tracked_flush/job_tracked_flush_test.cpp index 2238e3c4f0c..7c22aab2285 100644 --- a/searchcore/src/tests/proton/metrics/job_tracked_flush/job_tracked_flush_test.cpp +++ b/searchcore/src/tests/proton/metrics/job_tracked_flush/job_tracked_flush_test.cpp @@ -1,6 +1,4 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("job_tracked_flush_test"); #include <vespa/searchcore/proton/metrics/job_tracked_flush_target.h> #include <vespa/searchcore/proton/metrics/job_tracked_flush_task.h> @@ -8,16 +6,18 @@ LOG_SETUP("job_tracked_flush_test"); #include <vespa/searchcore/proton/test/simple_job_tracker.h> #include <vespa/searchlib/common/flush_token.h> #include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/util/gate.h> +#include <vespa/log/log.h> +LOG_SETUP("job_tracked_flush_test"); + using namespace proton; using namespace searchcorespi; using search::SerialNum; using test::SimpleJobTracker; -using vespalib::makeTask; -using vespalib::makeClosure; +using vespalib::makeLambdaTask; using vespalib::Gate; using vespalib::ThreadStackExecutor; @@ -47,7 +47,7 @@ struct MyFlushTarget : public test::DummyFlushTarget {} // Implements searchcorespi::IFlushTarget - virtual FlushTask::UP initFlush(SerialNum currentSerial, std::shared_ptr<search::IFlushToken>) override { + FlushTask::UP initFlush(SerialNum currentSerial, std::shared_ptr<search::IFlushToken>) override { if (currentSerial > 0) { _initFlushSerial = currentSerial; _initGate.await(5000); @@ -94,7 +94,7 @@ TEST_F("require that flush task init is tracked", Fixture) EXPECT_EQUAL(1u, f._tracker->_started.getCount()); EXPECT_EQUAL(1u, f._tracker->_ended.getCount()); - f._exec.execute(makeTask(makeClosure(&f, &Fixture::initFlush, FLUSH_SERIAL))); + f._exec.execute(makeLambdaTask([&]() {f.initFlush(FLUSH_SERIAL); })); f._tracker->_started.await(5000); EXPECT_EQUAL(0u, f._tracker->_started.getCount()); EXPECT_EQUAL(1u, f._tracker->_ended.getCount()); @@ -112,7 +112,7 @@ TEST_F("require that flush task init is tracked", Fixture) TEST_F("require that flush task execution is tracked", Fixture(2)) { - f._exec.execute(makeTask(makeClosure(&f, &Fixture::initFlush, FLUSH_SERIAL))); + f._exec.execute(makeLambdaTask([&]() { f.initFlush(FLUSH_SERIAL); })); f._target->_initGate.countDown(); f._taskGate.await(5000); diff --git a/searchcore/src/vespa/searchcore/proton/server/buckethandler.cpp b/searchcore/src/vespa/searchcore/proton/server/buckethandler.cpp index 57f1ee74e60..ec2d1b70e4a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/buckethandler.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/buckethandler.cpp @@ -2,7 +2,7 @@ #include "buckethandler.h" #include "ibucketstatechangedhandler.h" -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <vespa/log/log.h> LOG_SETUP(".proton.server.buckethandler"); @@ -15,8 +15,7 @@ using storage::spi::BucketInfo; using storage::spi::BucketInfoResult; using storage::spi::Result; using vespalib::Executor; -using vespalib::makeTask; -using vespalib::makeClosure; +using vespalib::makeLambdaTask; namespace proton { @@ -104,9 +103,9 @@ BucketHandler::handleSetCurrentState(const BucketId &bucketId, storage::spi::BucketInfo::ActiveState newState, IGenericResultHandler &resultHandler) { - _executor.execute(makeTask(makeClosure(this, - &proton::BucketHandler::performSetCurrentState, - bucketId, newState, &resultHandler))); + _executor.execute(makeLambdaTask([this, bucketId, newState, resultHandlerP = &resultHandler]() { + performSetCurrentState(bucketId, newState, resultHandlerP); + })); } void @@ -137,21 +136,17 @@ void BucketHandler::handlePopulateActiveBuckets(document::BucketId::List &buckets, IGenericResultHandler &resultHandler) { - _executor.execute(makeTask(makeClosure(this, - &proton::BucketHandler:: - performPopulateActiveBuckets, - buckets, - &resultHandler))); + _executor.execute(makeLambdaTask([this, buckets, &resultHandler]() { + performPopulateActiveBuckets(std::move(buckets), &resultHandler); + })); } void -BucketHandler::notifyClusterStateChanged(const IBucketStateCalculator::SP & - newCalc) +BucketHandler::notifyClusterStateChanged(const IBucketStateCalculator::SP & newCalc) { bool oldNodeUp = _nodeUp; _nodeUp = newCalc->nodeUp(); - LOG(spam, - "notifyClusterStateChanged: %s -> %s", + LOG(spam, "notifyClusterStateChanged: %s -> %s", oldNodeUp ? "up" : "down", _nodeUp ? "up" : "down"); if (oldNodeUp && !_nodeUp) { @@ -170,8 +165,7 @@ BucketHandler:: removeBucketStateChangedHandler(IBucketStateChangedHandler *handler) { // Called by executor thread - auto it = std::find(_changedHandlers.begin(), _changedHandlers.end(), - handler); + auto it = std::find(_changedHandlers.begin(), _changedHandlers.end(), handler); if (it != _changedHandlers.end()) { _changedHandlers.erase(it); } diff --git a/searchcore/src/vespa/searchcore/proton/server/clusterstatehandler.cpp b/searchcore/src/vespa/searchcore/proton/server/clusterstatehandler.cpp index 2d10e5b1dc7..f730d286b34 100644 --- a/searchcore/src/vespa/searchcore/proton/server/clusterstatehandler.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/clusterstatehandler.cpp @@ -2,7 +2,7 @@ #include "clusterstatehandler.h" #include "iclusterstatechangedhandler.h" -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <sstream> #include <vespa/log/log.h> @@ -13,8 +13,7 @@ using storage::spi::BucketIdListResult; using storage::spi::ClusterState; using storage::spi::Result; using vespalib::Executor; -using vespalib::makeTask; -using vespalib::makeClosure; +using vespalib::makeLambdaTask; namespace proton { @@ -49,10 +48,8 @@ public: } - void -ClusterStateHandler::performSetClusterState(const ClusterState *calc, - IGenericResultHandler *resultHandler) +ClusterStateHandler::performSetClusterState(const ClusterState *calc, IGenericResultHandler *resultHandler) { LOG(debug, "performSetClusterState(): " @@ -64,17 +61,13 @@ ClusterStateHandler::performSetClusterState(const ClusterState *calc, _changedHandlers.size()); if (!_changedHandlers.empty()) { auto newCalc = std::make_shared<ClusterStateAdapter>(*calc); - typedef std::vector<IClusterStateChangedHandler *> Chv; - Chv &chs(_changedHandlers); - for (Chv::const_iterator it = chs.begin(), ite = chs.end(); it != ite; - ++it) { - (*it)->notifyClusterStateChanged(newCalc); + for (const auto & handler : _changedHandlers ) { + handler->notifyClusterStateChanged(newCalc); } } resultHandler->handle(Result()); } - void ClusterStateHandler::performGetModifiedBuckets( IBucketIdListResultHandler *resultHandler) @@ -99,14 +92,12 @@ ClusterStateHandler::performGetModifiedBuckets( _modifiedBuckets.clear(); } - void ClusterStateHandler::notifyBucketModified(const document::BucketId &bucket) { _modifiedBuckets.insert(bucket); } - ClusterStateHandler::ClusterStateHandler(Executor &executor) : IBucketModifiedHandler(), IClusterStateChangedNotifier(), @@ -116,13 +107,11 @@ ClusterStateHandler::ClusterStateHandler(Executor &executor) { } - ClusterStateHandler::~ClusterStateHandler() { assert(_changedHandlers.empty()); } - void ClusterStateHandler:: addClusterStateChangedHandler(IClusterStateChangedHandler *handler) @@ -130,40 +119,30 @@ addClusterStateChangedHandler(IClusterStateChangedHandler *handler) _changedHandlers.push_back(handler); } - void ClusterStateHandler:: removeClusterStateChangedHandler(IClusterStateChangedHandler *handler) { - auto it = std::find(_changedHandlers.begin(), _changedHandlers.end(), - handler); + auto it = std::find(_changedHandlers.begin(), _changedHandlers.end(), handler); if (it != _changedHandlers.end()) { _changedHandlers.erase(it); } } - void -ClusterStateHandler::handleSetClusterState(const ClusterState &calc, - IGenericResultHandler &resultHandler) +ClusterStateHandler::handleSetClusterState(const ClusterState &calc, IGenericResultHandler &resultHandler) { - _executor.execute(makeTask(makeClosure(this, - &proton::ClusterStateHandler:: - performSetClusterState, - &calc, - &resultHandler))); + _executor.execute(makeLambdaTask([&]() { + performSetClusterState(&calc, &resultHandler); + })); } - void -ClusterStateHandler::handleGetModifiedBuckets( - IBucketIdListResultHandler &resultHandler) +ClusterStateHandler::handleGetModifiedBuckets(IBucketIdListResultHandler &resultHandler) { - _executor.execute(makeTask(makeClosure(this, - &proton::ClusterStateHandler:: - performGetModifiedBuckets, - &resultHandler))); + _executor.execute(makeLambdaTask([&]() { + performGetModifiedBuckets(&resultHandler); + })); } - -} // namespace proton +} diff --git a/searchcore/src/vespa/searchcore/proton/server/frozenbuckets.cpp b/searchcore/src/vespa/searchcore/proton/server/frozenbuckets.cpp index d5deb4482c4..54ef4ea2da4 100644 --- a/searchcore/src/vespa/searchcore/proton/server/frozenbuckets.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/frozenbuckets.cpp @@ -3,12 +3,11 @@ #include "frozenbuckets.h" #include "ibucketfreezelistener.h" #include <vespa/searchcorespi/index/i_thread_service.h> -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <algorithm> using document::BucketId; -using vespalib::makeClosure; -using vespalib::makeTask; +using vespalib::makeLambdaTask; namespace proton { @@ -119,7 +118,7 @@ void FrozenBuckets::thawBucket(BucketId bucket) { if (_frozen.thawBucket(bucket)) { - _masterThread.execute(makeTask(makeClosure(this, &FrozenBuckets::notifyThawed, bucket))); + _masterThread.execute(makeLambdaTask([this, bucket]() { notifyThawed(bucket); })); } } diff --git a/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp b/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp index e822b1de33e..9d148a43964 100644 --- a/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/maintenancecontroller.cpp @@ -5,7 +5,6 @@ #include "document_db_maintenance_config.h" #include "i_blockable_maintenance_job.h" #include <vespa/searchcorespi/index/i_thread_service.h> -#include <vespa/vespalib/util/closuretask.h> #include <vespa/vespalib/util/lambdatask.h> #include <vespa/vespalib/util/scheduledexecutor.h> @@ -14,8 +13,6 @@ LOG_SETUP(".proton.server.maintenancecontroller"); using document::BucketId; using vespalib::Executor; -using vespalib::makeClosure; -using vespalib::makeTask; using vespalib::makeLambdaTask; namespace proton { @@ -102,7 +99,9 @@ MaintenanceController::killJobs() _jobs.clear(); } // Hold jobs until existing tasks have been drained - _masterThread.execute(makeTask(makeClosure(this, &MaintenanceController::performHoldJobs, tmpJobs))); + _masterThread.execute(makeLambdaTask([this, jobs=std::move(tmpJobs)]() { + performHoldJobs(std::move(jobs)); + })); } void diff --git a/searchcore/src/vespa/searchcore/proton/server/maintenancejobrunner.cpp b/searchcore/src/vespa/searchcore/proton/server/maintenancejobrunner.cpp index 81233779ffa..ee2cb741991 100644 --- a/searchcore/src/vespa/searchcore/proton/server/maintenancejobrunner.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/maintenancejobrunner.cpp @@ -1,15 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "maintenancejobrunner.h" -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <vespa/fastos/thread.h> #include <vespa/log/log.h> LOG_SETUP(".proton.server.maintenancejobrunner"); using vespalib::Executor; -using vespalib::makeClosure; -using vespalib::makeTask; +using vespalib::makeLambdaTask; namespace proton { @@ -28,7 +27,7 @@ MaintenanceJobRunner::addExecutorTask() Guard guard(_lock); if (!_queued) { _queued = true; - _executor.execute(makeTask(makeClosure(this, &MaintenanceJobRunner::runJobInExecutor))); + _executor.execute(makeLambdaTask([this]() { runJobInExecutor(); })); } } } @@ -57,8 +56,7 @@ MaintenanceJobRunner::runJobInExecutor() } } -MaintenanceJobRunner::MaintenanceJobRunner(Executor &executor, - IMaintenanceJob::UP job) +MaintenanceJobRunner::MaintenanceJobRunner(Executor &executor, IMaintenanceJob::UP job) : _executor(executor), _job(std::move(job)), _stopped(false), diff --git a/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp b/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp index 8c812928842..f28526a4b2a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.cpp @@ -4,7 +4,7 @@ #include "proton.h" #include <vespa/searchcore/proton/summaryengine/docsum_by_slime.h> #include <vespa/searchcore/proton/matchengine/matchengine.h> -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <vespa/fnet/frt/supervisor.h> #include <vespa/fnet/transport.h> @@ -16,18 +16,7 @@ using vespalib::compression::CompressionConfig; namespace { -struct Pair { - string key; - string value; - Pair(const string &k, const string &v) noexcept - : key(k), - value(v) - { - } - ~Pair(); -}; - -Pair::~Pair() = default; +using Pair = std::pair<string, string>; VESPA_THREAD_STACK_TAG(proton_rpc_executor) @@ -50,8 +39,9 @@ RPCHooksBase::checkState(std::unique_ptr<StateArg> arg) LOG(debug, "Will reschedule"); FRT_RPCRequest * req = arg->_req; Session & session = *arg->_session; - Executor::Task::UP failedTask = _executor.execute(makeTask( - makeClosure(this, &RPCHooksBase::checkState, std::move(arg)))); + Executor::Task::UP failedTask = _executor.execute(makeLambdaTask([this, arg=std::move(arg)]() mutable { + checkState(std::move(arg)); + })); if (failedTask) { reportState(session, req); req->Return(); @@ -81,13 +71,15 @@ RPCHooksBase::reportState(Session & session, FRT_RPCRequest * req) res.emplace_back("onlineState", "onlineSoon"); } if (session.getGen() < 0) { - if (delayedConfigsChanged) + if (delayedConfigsChanged) { res.emplace_back("delayedConfigs", delayedConfigs); + } res.emplace_back("onlineDocs", make_string("%" PRId64, numDocs)); session.setGen(0); } else if (changed) { - if (delayedConfigsChanged) + if (delayedConfigsChanged) { res.emplace_back("delayedConfigs", delayedConfigs); + } res.emplace_back("onlineDocs", make_string("%" PRId64, numDocs)); session.setGen(session.getGen() + 1); } @@ -100,12 +92,12 @@ RPCHooksBase::reportState(Session & session, FRT_RPCRequest * req) FRT_StringValue *k = ret.AddStringArray(res.size()); FRT_StringValue *v = ret.AddStringArray(res.size()); for (uint32_t i = 0; i < res.size(); ++i) { - ret.SetString(&k[i], res[i].key.c_str()); - ret.SetString(&v[i], res[i].value.c_str()); + ret.SetString(&k[i], res[i].first.c_str()); + ret.SetString(&v[i], res[i].second.c_str()); } LOG(debug, "gen=%" PRId64, session.getGen()); for (const auto & r : res) { - LOG(debug, "key=%s, value=%s", r.key.c_str(), r.value.c_str()); + LOG(debug, "key=%s, value=%s", r.first.c_str(), r.second.c_str()); } ret.AddInt32(session.getGen()); } @@ -241,9 +233,8 @@ RPCHooksBase::close() } void -RPCHooksBase::letProtonDo(Closure::UP closure) +RPCHooksBase::letProtonDo(Executor::Task::UP task) { - Executor::Task::UP task = makeTask(std::move(closure)); _proton.getExecutor().execute(std::move(task)); } @@ -288,8 +279,10 @@ RPCHooksBase::rpc_GetState(FRT_RPCRequest *req) reportState(*sharedSession, req); } else { steady_time dueTime(steady_clock::now() + std::chrono::milliseconds(timeoutMS)); - auto stateArg = std::make_unique<StateArg>(sharedSession, req, dueTime); - if (_executor.execute(makeTask(makeClosure(this, &RPCHooksBase::checkState, std::move(stateArg))))) { + auto failed = _executor.execute(makeLambdaTask([this, arg=std::make_unique<StateArg>(sharedSession, req, dueTime)]() mutable { + checkState(std::move(arg)); + })); + if (failed) { reportState(*sharedSession, req); req->Return(); } else { @@ -303,7 +296,7 @@ RPCHooksBase::rpc_GetProtonStatus(FRT_RPCRequest *req) { LOG(debug, "RPCHooksBase::rpc_GetProtonStatus started"); req->Detach(); - _executor.execute(makeTask(makeClosure(this, &RPCHooksBase::getProtonStatus, req))); + _executor.execute(makeLambdaTask([this, req]() { getProtonStatus(req); })); } void @@ -354,7 +347,7 @@ RPCHooksBase::rpc_getIncrementalState(FRT_RPCRequest *req) } else { steady_time dueTime(steady_clock::now() + std::chrono::milliseconds(timeoutMS)); auto stateArg = std::make_unique<StateArg>(sharedSession, req, dueTime); - if (_executor.execute(makeTask(makeClosure(this, &RPCHooksBase::checkState, std::move(stateArg))))) { + if (_executor.execute(makeLambdaTask([this, arg=std::move(stateArg)]() mutable { checkState(std::move(arg)); }))) { reportState(*sharedSession, req); req->Return(); } else { @@ -383,7 +376,7 @@ RPCHooksBase::rpc_triggerFlush(FRT_RPCRequest *req) { LOG(info, "RPCHooksBase::rpc_triggerFlush started"); req->Detach(); - letProtonDo(makeClosure(this, &RPCHooksBase::triggerFlush, req)); + letProtonDo(makeLambdaTask([this, req]() { triggerFlush(req); })); } void @@ -391,7 +384,7 @@ RPCHooksBase::rpc_prepareRestart(FRT_RPCRequest *req) { LOG(info, "RPCHooksBase::rpc_prepareRestart started"); req->Detach(); - letProtonDo(makeClosure(this, &RPCHooksBase::prepareRestart, req)); + letProtonDo(makeLambdaTask([this, req]() { prepareRestart(req); })); } void @@ -399,7 +392,7 @@ RPCHooksBase::rpc_getDocSums(FRT_RPCRequest *req) { LOG(debug, "proton.getDocsums()"); req->Detach(); - _executor.execute(makeTask(makeClosure(this, &RPCHooksBase::getDocsums, req))); + _executor.execute(makeLambdaTask([this, req]() { getDocsums(req); })); } void @@ -418,7 +411,6 @@ RPCHooksBase::getSession(FRT_RPCRequest *req) return *sessionspp; } - void RPCHooksBase::initSession(FRT_RPCRequest *req) { diff --git a/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.h b/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.h index f8714a8aa13..8e3679d8fa5 100644 --- a/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.h +++ b/searchcore/src/vespa/searchcore/proton/server/rpc_hooks.h @@ -4,7 +4,6 @@ #include <vespa/slobrok/sbregister.h> #include <vespa/vespalib/util/executor.h> -#include <vespa/vespalib/util/closure.h> #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/searchlib/engine/proto_rpc_adapter.h> @@ -70,7 +69,7 @@ private: vespalib::ThreadStackExecutor _executor; void initRPC(); - void letProtonDo(vespalib::Closure::UP closure); + void letProtonDo(vespalib::Executor::Task::UP task); void triggerFlush(FRT_RPCRequest *req); void prepareRestart(FRT_RPCRequest *req); diff --git a/searchlib/src/vespa/searchlib/docstore/storebybucket.cpp b/searchlib/src/vespa/searchlib/docstore/storebybucket.cpp index 6418305e01f..cd919c5ff03 100644 --- a/searchlib/src/vespa/searchlib/docstore/storebybucket.cpp +++ b/searchlib/src/vespa/searchlib/docstore/storebybucket.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "storebybucket.h" -#include <vespa/vespalib/util/closuretask.h> +#include <vespa/vespalib/util/lambdatask.h> #include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/vespalib/data/databuffer.h> #include <algorithm> @@ -9,8 +9,7 @@ namespace search::docstore { using document::BucketId; -using vespalib::makeTask; -using vespalib::makeClosure; +using vespalib::makeLambdaTask; StoreByBucket::StoreByBucket(MemoryDataStore & backingMemory, Executor & executor, const CompressionConfig & compression) noexcept : _chunkSerial(0), @@ -36,7 +35,9 @@ StoreByBucket::add(BucketId bucketId, uint32_t chunkId, uint32_t lid, const void Chunk::UP tmpChunk = createChunk(); _current.swap(tmpChunk); incChunksPosted(); - _executor.execute(makeTask(makeClosure(this, &StoreByBucket::closeChunk, std::move(tmpChunk)))); + _executor.execute(makeLambdaTask([this, chunk=std::move(tmpChunk)]() mutable { + closeChunk(std::move(chunk)); + })); } Index idx(bucketId, _current->getId(), chunkId, lid); _current->append(lid, buffer, sz); @@ -87,7 +88,9 @@ void StoreByBucket::drain(IWrite & drainer) { incChunksPosted(); - _executor.execute(makeTask(makeClosure(this, &StoreByBucket::closeChunk, std::move(_current)))); + _executor.execute(makeLambdaTask([this, chunk=std::move(_current)]() mutable { + closeChunk(std::move(chunk)); + })); waitAllProcessed(); std::vector<Chunk::UP> chunks; chunks.resize(_chunks.size()); |