diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-08 13:22:15 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-08 13:22:15 +0000 |
commit | 68f3ef41f603a17bca17788e99a9928bb540ae24 (patch) | |
tree | f2b89dbde4d0f54cb6170de69a2f79395366b42a | |
parent | b6a0b4fcfa93cfd9833dd9ee1ea8c2014abfe0f1 (diff) |
Use std::mutex over vespalib::Lock and reduce code visibility.
43 files changed, 98 insertions, 80 deletions
diff --git a/config/src/tests/api/api.cpp b/config/src/tests/api/api.cpp index 0af2b848ea5..a48f36aea9a 100644 --- a/config/src/tests/api/api.cpp +++ b/config/src/tests/api/api.cpp @@ -1,13 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/config.h> +#include <vespa/config/common/configcontext.h> #include <config-my.h> using namespace config; TEST("require that can subscribe with empty config id") { ConfigSet set; - ConfigContext::SP ctx(new ConfigContext(set)); + auto ctx = std::make_shared<ConfigContext>(set); MyConfigBuilder builder; builder.myField = "myfoo"; set.addBuilder("", &builder); diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp index 856b1198ce8..508322bb74e 100644 --- a/config/src/tests/configfetcher/configfetcher.cpp +++ b/config/src/tests/configfetcher/configfetcher.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/helper/configfetcher.h> +#include <vespa/config/common/configcontext.h> #include <vespa/vespalib/util/exception.h> #include "config-my.h" #include <atomic> @@ -12,7 +13,7 @@ class MyCallback : public IFetcherCallback<MyConfig> { public: MyCallback(const std::string & badConfig=""); - ~MyCallback(); + ~MyCallback() override; void configure(std::unique_ptr<MyConfig> config) override { _config = std::move(config); @@ -126,7 +127,7 @@ struct ConfigFixture { ConfigContext::SP context; ConfigFixture() : builder(), set(), context() { set.addBuilder("cfgid", &builder); - context.reset(new ConfigContext(set)); + context = std::make_shared<ConfigContext>(set); } }; diff --git a/config/src/tests/configretriever/configretriever.cpp b/config/src/tests/configretriever/configretriever.cpp index 2c1954bcd95..d4ebe2da994 100644 --- a/config/src/tests/configretriever/configretriever.cpp +++ b/config/src/tests/configretriever/configretriever.cpp @@ -7,7 +7,9 @@ #include <vespa/config/retriever/simpleconfigretriever.h> #include <vespa/config/retriever/simpleconfigurer.h> #include <vespa/config/common/configholder.h> +#include <vespa/config/common/configcontext.h> #include <vespa/config/subscription/configsubscription.h> +#include <vespa/config/subscription/sourcespec.h> #include <vespa/config/common/exceptions.h> #include "config-bootstrap.h" #include "config-foo.h" @@ -39,7 +41,7 @@ struct ConfigTestFixture { bootstrapBuilder(), componentConfig(), set(), - context(new ConfigContext(set)), + context(std::make_shared<ConfigContext>(set)), idcounter(-1) { set.addBuilder(configId, &bootstrapBuilder); diff --git a/config/src/tests/configuri/configuri_test.cpp b/config/src/tests/configuri/configuri_test.cpp index c813761e763..38d49848596 100644 --- a/config/src/tests/configuri/configuri_test.cpp +++ b/config/src/tests/configuri/configuri_test.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/config.h> +#include <vespa/config/common/configcontext.h> #include "config-my.h" using namespace config; diff --git a/config/src/tests/failover/failover.cpp b/config/src/tests/failover/failover.cpp index 0ca09b228f3..99b6967c929 100644 --- a/config/src/tests/failover/failover.cpp +++ b/config/src/tests/failover/failover.cpp @@ -4,10 +4,12 @@ #include <vespa/config/common/misc.h> #include <vespa/config/frt/protocol.h> #include <vespa/config/config.h> +#include <vespa/config/common/configcontext.h> #include <vespa/fnet/frt/frt.h> #include "config-my.h" #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/data/simple_buffer.h> + #include <vespa/log/log.h> LOG_SETUP("failover"); @@ -189,7 +191,7 @@ struct ConfigCheckFixture { NetworkFixture & nf; ConfigCheckFixture(NetworkFixture & f2) - : ctx(new ConfigContext(testTimingValues, f2.spec)), + : ctx(std::make_shared<ConfigContext>(testTimingValues, f2.spec)), nf(f2) { } @@ -223,7 +225,7 @@ struct ConfigReloadFixture { ConfigHandle<MyConfig>::UP handle; ConfigReloadFixture(NetworkFixture & f2) - : ctx(new ConfigContext(testTimingValues, f2.spec)), + : ctx(std::make_shared<ConfigContext>(testTimingValues, f2.spec)), nf(f2), s(ctx), handle(s.subscribe<MyConfig>("myId")) diff --git a/config/src/tests/file_subscription/file_subscription.cpp b/config/src/tests/file_subscription/file_subscription.cpp index ceaf16c9191..836ca6593f8 100644 --- a/config/src/tests/file_subscription/file_subscription.cpp +++ b/config/src/tests/file_subscription/file_subscription.cpp @@ -4,6 +4,8 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/file/filesource.h> #include <vespa/config/common/exceptions.h> +#include <vespa/config/common/sourcefactory.h> +#include <vespa/config/common/configcontext.h> #include <vespa/vespalib/util/sync.h> #include <fstream> #include <config-my.h> @@ -61,7 +63,7 @@ TEST("requireThatFileSpecGivesCorrectSource") { SourceFactory::UP factory(spec.createSourceFactory(TimingValues())); ASSERT_TRUE(factory); - IConfigHolder::SP holder(new ConfigHolder()); + auto holder = std::make_shared<ConfigHolder>(); Source::UP src = factory->createSource(holder, ConfigKey("my", "my", "bar", "foo")); ASSERT_TRUE(src); @@ -89,7 +91,7 @@ TEST("requireThatFileSubscriptionReturnsCorrectConfig") { TEST("requireThatReconfigIsCalledWhenConfigChanges") { writeFile("my.cfg", "foo"); { - IConfigContext::SP context(new ConfigContext(FileSpec("my.cfg"))); + auto context = std::make_shared<ConfigContext>(FileSpec("my.cfg")); ConfigSubscriber s(context); std::unique_ptr<ConfigHandle<MyConfig> > handle = s.subscribe<MyConfig>(""); s.nextConfigNow(); diff --git a/config/src/tests/getconfig/getconfig.cpp b/config/src/tests/getconfig/getconfig.cpp index 0cbac7aa456..b091e347ff2 100644 --- a/config/src/tests/getconfig/getconfig.cpp +++ b/config/src/tests/getconfig/getconfig.cpp @@ -1,9 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/config/config.h> #include <vespa/config/helper/configgetter.hpp> -#include <vespa/config/raw/rawsource.h> +#include <vespa/config/common/configcontext.h> #include "config-my.h" using namespace config; @@ -16,7 +15,7 @@ struct ConfigFixture { ConfigContext::SP context; ConfigFixture() : builder(), set(), context() { set.addBuilder("cfgid", &builder); - context.reset(new ConfigContext(set)); + context = std::make_shared<ConfigContext>(set); } }; @@ -27,7 +26,7 @@ TEST("requireThatGetConfigReturnsCorrectConfig") RawSpec spec("myField \"foo\"\n"); std::unique_ptr<MyConfig> cfg = ConfigGetter<MyConfig>::getConfig("myid", spec); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("my", cfg->defName()); ASSERT_EQUAL("foo", cfg->myField); } @@ -37,7 +36,7 @@ TEST("requireThatGetConfigReturnsCorrectConfig") { FileSpec spec(TEST_PATH("my.cfg")); std::unique_ptr<MyConfig> cfg = ConfigGetter<MyConfig>::getConfig("", spec); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("my", cfg->defName()); ASSERT_EQUAL("foobar", cfg->myField); } diff --git a/config/src/tests/raw_subscription/raw_subscription.cpp b/config/src/tests/raw_subscription/raw_subscription.cpp index 478b4611bac..39062f4e7ac 100644 --- a/config/src/tests/raw_subscription/raw_subscription.cpp +++ b/config/src/tests/raw_subscription/raw_subscription.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/config.h> #include <vespa/config/common/configholder.h> +#include <vespa/config/common/sourcefactory.h> #include <vespa/config/raw/rawsource.h> #include "config-my.h" @@ -10,7 +11,7 @@ using namespace config; TEST("require that raw spec can create source factory") { RawSpec spec("myField \"foo\"\n"); - SourceFactory::UP raw = spec.createSourceFactory(TimingValues()); + auto raw = spec.createSourceFactory(TimingValues()); ASSERT_TRUE(raw); IConfigHolder::SP holder(new ConfigHolder()); Source::UP src = raw->createSource(holder, ConfigKey("myid", "my", "bar", "foo")); diff --git a/config/src/tests/unittest/unittest.cpp b/config/src/tests/unittest/unittest.cpp index 4b46dcef900..46aefe152af 100644 --- a/config/src/tests/unittest/unittest.cpp +++ b/config/src/tests/unittest/unittest.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/config.h> +#include <vespa/config/common/configcontext.h> #include "config-my.h" #include "config-foo.h" #include "config-bar.h" @@ -15,13 +16,13 @@ using namespace std::chrono_literals; namespace { void verifyConfig(const std::string & expected, std::unique_ptr<FooConfig> cfg) { - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL(expected, cfg->fooValue); } void verifyConfig(const std::string & expected, std::unique_ptr<BarConfig> cfg) { - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL(expected, cfg->barValue); } } @@ -37,7 +38,7 @@ TEST("requireThatUnitTestsCanBeCreated") { TEST("requireThatConfigCanBeReloaded") { ConfigSet set; - ConfigContext::SP ctx(new ConfigContext(set)); + auto ctx = std::make_shared<ConfigContext>(set); MyConfigBuilder builder; builder.myField = "myfoo"; set.addBuilder("myid", &builder); @@ -46,7 +47,7 @@ TEST("requireThatConfigCanBeReloaded") { ConfigHandle<MyConfig>::UP handle = subscriber.subscribe<MyConfig>("myid"); ASSERT_TRUE(subscriber.nextConfigNow()); std::unique_ptr<MyConfig> cfg(handle->getConfig()); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("myfoo", cfg->myField); ctx->reload(); ASSERT_FALSE(subscriber.nextConfig(1000ms)); @@ -54,13 +55,13 @@ TEST("requireThatConfigCanBeReloaded") { ctx->reload(); ASSERT_TRUE(subscriber.nextConfig(10000ms)); cfg = handle->getConfig(); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("foobar", cfg->myField); } TEST("requireThatCanSubscribeWithSameIdToDifferentDefs") { ConfigSet set; - ConfigContext::SP ctx(new ConfigContext(set)); + auto ctx = std::make_shared<ConfigContext>(set); FooConfigBuilder fooBuilder; BarConfigBuilder barBuilder; diff --git a/config/src/vespa/config/common/configcontext.cpp b/config/src/vespa/config/common/configcontext.cpp index ed549f0cb6a..0eed91296a6 100644 --- a/config/src/vespa/config/common/configcontext.cpp +++ b/config/src/vespa/config/common/configcontext.cpp @@ -8,26 +8,26 @@ namespace config { ConfigContext::ConfigContext(const SourceSpec & spec) : _timingValues(), _generation(1), - _manager(spec.createSourceFactory(_timingValues), _generation) + _manager(std::make_unique<ConfigManager>(spec.createSourceFactory(_timingValues), _generation)) { } ConfigContext::ConfigContext(const TimingValues & timingValues, const SourceSpec & spec) : _timingValues(timingValues), _generation(1), - _manager(spec.createSourceFactory(_timingValues), _generation) + _manager(std::make_unique<ConfigManager>(spec.createSourceFactory(_timingValues), _generation)) { } IConfigManager & ConfigContext::getManagerInstance() { - return _manager; + return *_manager; } void ConfigContext::reload() { _generation++; - _manager.reload(_generation); + _manager->reload(_generation); } } // namespace config diff --git a/config/src/vespa/config/common/configcontext.h b/config/src/vespa/config/common/configcontext.h index 7d9836fe70b..dd3296a9b01 100644 --- a/config/src/vespa/config/common/configcontext.h +++ b/config/src/vespa/config/common/configcontext.h @@ -3,7 +3,7 @@ #include "iconfigcontext.h" #include "timingvalues.h" -#include "configmanager.h" +#include "iconfigmanager.h" #include <vespa/config/subscription/sourcespec.h> namespace config { @@ -19,7 +19,7 @@ public: private: TimingValues _timingValues; int64_t _generation; - ConfigManager _manager; + std::unique_ptr<IConfigManager> _manager; }; diff --git a/config/src/vespa/config/common/configmanager.cpp b/config/src/vespa/config/common/configmanager.cpp index 11fe66a1c64..df8615c9c40 100644 --- a/config/src/vespa/config/common/configmanager.cpp +++ b/config/src/vespa/config/common/configmanager.cpp @@ -18,8 +18,7 @@ ConfigManager::ConfigManager(SourceFactory::UP sourceFactory, int64_t initialGen _sourceFactory(std::move(sourceFactory)), _generation(initialGeneration), _subscriptionMap(), - _lock(), - _firstLock() + _lock() { } ConfigManager::~ConfigManager() = default; @@ -50,7 +49,7 @@ ConfigManager::subscribe(const ConfigKey & key, milliseconds timeoutInMillis) throw ConfigTimeoutException(oss.str()); } LOG(debug, "done subscribing"); - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); _subscriptionMap[id] = subscription; return subscription; } @@ -58,7 +57,7 @@ ConfigManager::subscribe(const ConfigKey & key, milliseconds timeoutInMillis) void ConfigManager::unsubscribe(const ConfigSubscription::SP & subscription) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); const SubscriptionId id(subscription->getSubscriptionId()); if (_subscriptionMap.find(id) != _subscriptionMap.end()) _subscriptionMap.erase(id); @@ -68,9 +67,9 @@ void ConfigManager::reload(int64_t generation) { _generation = generation; - vespalib::LockGuard guard(_lock); - for (SubscriptionMap::iterator it(_subscriptionMap.begin()), mt(_subscriptionMap.end()); it != mt; it++) { - it->second->reload(_generation); + std::lock_guard guard(_lock); + for (auto & entry : _subscriptionMap) { + entry.second->reload(_generation); } } diff --git a/config/src/vespa/config/common/configmanager.h b/config/src/vespa/config/common/configmanager.h index 6210a03c0d1..0252c6aa572 100644 --- a/config/src/vespa/config/common/configmanager.h +++ b/config/src/vespa/config/common/configmanager.h @@ -4,8 +4,8 @@ #include <vespa/config/subscription/configsubscription.h> #include "iconfigmanager.h" #include "sourcefactory.h" -#include <vespa/vespalib/util/sync.h> #include <map> +#include <mutex> namespace config { @@ -22,7 +22,7 @@ class ConfigManager : public IConfigManager { public: ConfigManager(SourceFactory::UP sourceFactory, int64_t initialGeneration); - ~ConfigManager(); + ~ConfigManager() override; // Implements IConfigManager ConfigSubscription::SP subscribe(const ConfigKey & key, milliseconds timeoutInMillis) override; @@ -40,8 +40,7 @@ private: typedef std::map<SubscriptionId, ConfigSubscription::SP> SubscriptionMap; SubscriptionMap _subscriptionMap; - vespalib::Lock _lock; - vespalib::Lock _firstLock; + std::mutex _lock; }; } // namespace config diff --git a/config/src/vespa/config/frt/frtsource.cpp b/config/src/vespa/config/frt/frtsource.cpp index 449ad5df1ba..bee5158ecb8 100644 --- a/config/src/vespa/config/frt/frtsource.cpp +++ b/config/src/vespa/config/frt/frtsource.cpp @@ -89,7 +89,7 @@ void FRTSource::close() { { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); if (_closed) return; LOG(spam, "Killing task"); @@ -107,7 +107,7 @@ FRTSource::close() void FRTSource::scheduleNextGetConfig() { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); if (_closed) return; double sec = _agent->getWaitTime() / 1000.0; diff --git a/config/src/vespa/config/frt/frtsource.h b/config/src/vespa/config/frt/frtsource.h index 16e1bfac37a..eabac3bf012 100644 --- a/config/src/vespa/config/frt/frtsource.h +++ b/config/src/vespa/config/frt/frtsource.h @@ -9,8 +9,6 @@ #include <vespa/config/common/source.h> #include <vespa/fnet/frt/invoker.h> -#include <vespa/vespalib/util/sync.h> - namespace config { /** @@ -21,7 +19,7 @@ class FRTSource : public Source, { public: FRTSource(const ConnectionFactory::SP & connectionFactory, const FRTConfigRequestFactory & requestFactory, ConfigAgent::UP agent, const ConfigKey & key); - ~FRTSource(); + ~FRTSource() override; void RequestDone(FRT_RPCRequest * request) override; void close() override; @@ -40,7 +38,7 @@ private: const ConfigKey _key; std::unique_ptr<FNET_Task> _task; - vespalib::Lock _lock; // Protects _task and _closed + std::mutex _lock; // Protects _task and _closed bool _closed; }; diff --git a/config/src/vespa/config/helper/configfetcher.cpp b/config/src/vespa/config/helper/configfetcher.cpp index b013c137c2c..dda9c67f056 100644 --- a/config/src/vespa/config/helper/configfetcher.cpp +++ b/config/src/vespa/config/helper/configfetcher.cpp @@ -2,6 +2,7 @@ #include "configfetcher.h" #include <vespa/config/common/exceptions.h> +#include <vespa/config/common/configcontext.h> #include <vespa/vespalib/util/thread.h> #include <vespa/log/log.h> LOG_SETUP(".config.helper.configfetcher"); diff --git a/config/src/vespa/config/helper/legacysubscriber.hpp b/config/src/vespa/config/helper/legacysubscriber.hpp index bffe1d3feca..4aa383c6f9b 100644 --- a/config/src/vespa/config/helper/legacysubscriber.hpp +++ b/config/src/vespa/config/helper/legacysubscriber.hpp @@ -1,5 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/config/common/configcontext.h> + namespace config { template <typename ConfigType> @@ -9,10 +11,10 @@ LegacySubscriber::subscribe(const std::string & configId, IFetcherCallback<Confi if (isLegacyConfigId(configId)) { std::string legacyId(legacyConfigId2ConfigId(configId)); std::unique_ptr<SourceSpec> spec(legacyConfigId2Spec(configId)); - _fetcher.reset(new ConfigFetcher(IConfigContext::SP(new ConfigContext(*spec)))); + _fetcher = std::make_unique<ConfigFetcher>(std::make_shared<ConfigContext>(*spec)); _fetcher->subscribe<ConfigType>(legacyId, callback); } else { - _fetcher.reset(new ConfigFetcher()); + _fetcher = std::make_unique<ConfigFetcher>(); _fetcher->subscribe<ConfigType>(configId, callback); } _configId = configId; diff --git a/config/src/vespa/config/retriever/configretriever.cpp b/config/src/vespa/config/retriever/configretriever.cpp index f34ee6f70af..a77c8114322 100644 --- a/config/src/vespa/config/retriever/configretriever.cpp +++ b/config/src/vespa/config/retriever/configretriever.cpp @@ -2,6 +2,7 @@ #include "configretriever.h" #include <vespa/config/common/exceptions.h> +#include <vespa/config/subscription/sourcespec.h> #include <cassert> using std::chrono::milliseconds; diff --git a/config/src/vespa/config/retriever/configretriever.h b/config/src/vespa/config/retriever/configretriever.h index 9ef67edd7b8..1207a17af97 100644 --- a/config/src/vespa/config/retriever/configretriever.h +++ b/config/src/vespa/config/retriever/configretriever.h @@ -7,10 +7,12 @@ #include <vespa/config/common/configkey.h> #include <vespa/config/subscription/configsubscription.h> #include <vespa/vespalib/stllike/string.h> - +#include <mutex> namespace config { +class SourceSpec; + /** * A ConfigRetriever is a helper class for retrieving a set of dynamically * changing and depending configs. You should use this class whenever you have a diff --git a/config/src/vespa/config/subscription/configsubscriber.cpp b/config/src/vespa/config/subscription/configsubscriber.cpp index b226c149b9e..cb735e4353a 100644 --- a/config/src/vespa/config/subscription/configsubscriber.cpp +++ b/config/src/vespa/config/subscription/configsubscriber.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "configsubscriber.h" +#include <vespa/config/common/configcontext.h> namespace config { diff --git a/config/src/vespa/config/subscription/configsubscriber.h b/config/src/vespa/config/subscription/configsubscriber.h index 4787c6cd858..d7139b5d61f 100644 --- a/config/src/vespa/config/subscription/configsubscriber.h +++ b/config/src/vespa/config/subscription/configsubscriber.h @@ -7,6 +7,7 @@ #include "configsubscriptionset.h" #include "configprovider.h" #include "sourcespec.h" +#include <vespa/config/common/timingvalues.h> namespace config { diff --git a/config/src/vespa/config/subscription/configsubscription.h b/config/src/vespa/config/subscription/configsubscription.h index 80051edb86b..a48fddaa41c 100644 --- a/config/src/vespa/config/subscription/configsubscription.h +++ b/config/src/vespa/config/subscription/configsubscription.h @@ -1,10 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <memory> +#include "subscriptionid.h" #include <vespa/config/common/iconfigholder.h> #include <vespa/config/common/configkey.h> #include <vespa/config/common/source.h> -#include "subscriptionid.h" #include <atomic> #include <chrono> diff --git a/config/src/vespa/config/subscription/configsubscriptionset.h b/config/src/vespa/config/subscription/configsubscriptionset.h index 181f79f0ef2..3e91f1cc68d 100644 --- a/config/src/vespa/config/subscription/configsubscriptionset.h +++ b/config/src/vespa/config/subscription/configsubscriptionset.h @@ -2,13 +2,12 @@ // #pragma once -#include <vespa/config/common/iconfigholder.h> -#include <vespa/config/common/configcontext.h> #include "confighandle.h" #include "subscriptionid.h" #include "configsubscription.h" #include "configprovider.h" - +#include <vespa/config/common/iconfigcontext.h> +#include <vespa/config/common/iconfigmanager.h> #include <atomic> namespace config { diff --git a/config/src/vespa/config/subscription/subscriptionid.h b/config/src/vespa/config/subscription/subscriptionid.h index fe87debb58f..67dd905f523 100644 --- a/config/src/vespa/config/subscription/subscriptionid.h +++ b/config/src/vespa/config/subscription/subscriptionid.h @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include <cstdint> + namespace config { typedef uint64_t SubscriptionId; diff --git a/configutil/src/tests/config_status/config_status_test.cpp b/configutil/src/tests/config_status/config_status_test.cpp index 3cc5b2f4525..4d85b22a5c4 100644 --- a/configutil/src/tests/config_status/config_status_test.cpp +++ b/configutil/src/tests/config_status/config_status_test.cpp @@ -5,6 +5,7 @@ #include <vespa/config-model.h> #include <vespa/config/config.h> #include <vespa/config/subscription/sourcespec.h> +#include <vespa/config/common/configcontext.h> using namespace config; using vespalib::Portal; @@ -54,7 +55,7 @@ public: { flags.verbose = true; ConfigSet set; - ConfigContext::SP ctx(new ConfigContext(set)); + auto ctx = std::make_shared<ConfigContext>(set); cloud::config::ModelConfigBuilder builder; cloud::config::ModelConfigBuilder::Hosts::Services::Ports port; diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp index 378f12b5138..01245843e3b 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp @@ -60,7 +60,7 @@ DocumentRouteSelectorPolicy::configure(std::unique_ptr<messagebus::protocol::Doc } config[string(route.name)] = selector; } - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); _config.swap(config); _error.swap(error); } @@ -68,7 +68,7 @@ DocumentRouteSelectorPolicy::configure(std::unique_ptr<messagebus::protocol::Doc const string & DocumentRouteSelectorPolicy::getError() const { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); return _error; } @@ -84,7 +84,7 @@ DocumentRouteSelectorPolicy::select(mbus::RoutingContext &context) // Invoke private select method for each candidate recipient. { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); if (!_error.empty()) { context.setError(DocumentProtocol::ERROR_POLICY_FAILURE, _error); return; diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h index 6e13f615a35..02e8e4ff282 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h @@ -5,7 +5,6 @@ #include <vespa/document/select/node.h> #include <map> #include <vespa/messagebus/routing/iroutingpolicy.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/documentapi/common.h> #include <vespa/config/config.h> #include <vespa/config/helper/configfetcher.h> @@ -33,7 +32,7 @@ private: typedef std::map<string, SelectorPtr> ConfigMap; const document::DocumentTypeRepo &_repo; - vespalib::Lock _lock; + mutable std::mutex _lock; ConfigMap _config; string _error; config::ConfigFetcher _fetcher; diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.cpp index 6c4523fa34f..25112a00b99 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.cpp @@ -118,7 +118,7 @@ ExternPolicy::merge(mbus::RoutingContext &ctx) mbus::Hop ExternPolicy::getRecipient() { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); update(); if (_recipients.empty()) { return mbus::Hop(); diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.h index c56f8f214ec..cb0c4428e60 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/externpolicy.h @@ -4,9 +4,8 @@ #include <vespa/messagebus/routing/hop.h> #include <vespa/messagebus/routing/iroutingpolicy.h> #include <vespa/slobrok/imirrorapi.h> -#include <vector> -#include <vespa/vespalib/util/sync.h> #include <vespa/documentapi/common.h> +#include <mutex> class FRT_Supervisor; class FNET_Transport; @@ -21,7 +20,7 @@ namespace documentapi { class ExternPolicy : public mbus::IRoutingPolicy { private: using IMirrorAPI = slobrok::api::IMirrorAPI; - vespalib::Lock _lock; + std::mutex _lock; std::unique_ptr<FastOS_ThreadPool> _threadPool; std::unique_ptr<FNET_Transport> _transport; std::unique_ptr<FRT_Supervisor> _orb; diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.cpp index e82a184d8b2..800aa8c4520 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.cpp @@ -2,6 +2,7 @@ #include "externslobrokpolicy.h" #include <vespa/messagebus/routing/routingcontext.h> +#include <vespa/config/common/configcontext.h> #include <vespa/vespalib/text/stringtokenizer.h> #include <vespa/vespalib/util/time.h> #include <vespa/fnet/frt/frt.h> @@ -61,8 +62,8 @@ string ExternSlobrokPolicy::init() { } else if (_configSources.size() != 0) { slobrok::ConfiguratorFactory config( config::ConfigUri(_slobrokConfigId, - std::make_unique<config::ConfigContext>(config::ServerSpec(_configSources)))); - _mirror.reset(new MirrorAPI(*_orb, config)); + std::make_shared<config::ConfigContext>(config::ServerSpec(_configSources)))); + _mirror = std::make_unique<MirrorAPI>(*_orb, config); } if (_mirror.get()) { @@ -74,7 +75,7 @@ string ExternSlobrokPolicy::init() { IMirrorAPI::SpecList ExternSlobrokPolicy::lookup(mbus::RoutingContext& context, const string& pattern) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); const IMirrorAPI& mirror(_mirror.get()? *_mirror : context.getMirror()); diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h index d2966f852d5..61c79eb0a41 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h @@ -23,7 +23,7 @@ class ExternSlobrokPolicy : public AsyncInitializationPolicy protected: bool _firstTry; config::ServerSpec::HostSpecList _configSources; - vespalib::Lock _lock; + std::mutex _lock; std::unique_ptr<FastOS_ThreadPool> _threadPool; std::unique_ptr<FNET_Transport> _transport; std::unique_ptr<FRT_Supervisor> _orb; diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp index 7db941a12f2..9b23d593e82 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp @@ -49,7 +49,7 @@ LocalServicePolicy::getCacheKey(const mbus::RoutingContext &ctx) const mbus::Hop LocalServicePolicy::getRecipient(mbus::RoutingContext &ctx) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); CacheEntry &entry = update(ctx); if (entry._recipients.empty()) { mbus::Hop hop = ctx.getRoute().getHop(0); diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.h index 4dd22a77069..c188c9f5c4b 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.h @@ -4,9 +4,9 @@ #include <vespa/documentapi/common.h> #include <vespa/messagebus/routing/hop.h> #include <vespa/messagebus/routing/iroutingpolicy.h> -#include <vespa/vespalib/util/sync.h> #include <vector> #include <map> +#include <mutex> namespace documentapi { @@ -26,7 +26,7 @@ private: CacheEntry(); }; - vespalib::Lock _lock; + std::mutex _lock; string _address; std::map<string, CacheEntry> _cache; diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.cpp index 6f778a3e4d0..a58f3439df2 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.cpp @@ -56,7 +56,7 @@ RoundRobinPolicy::getCacheKey(const mbus::RoutingContext &ctx) const mbus::Hop RoundRobinPolicy::getRecipient(mbus::RoutingContext &ctx) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); CacheEntry &entry = update(ctx); if (entry._recipients.empty()) { return mbus::Hop(); diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.h index 0bfd2f04ea7..98e61fd1a1c 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/roundrobinpolicy.h @@ -4,8 +4,8 @@ #include <vespa/documentapi/common.h> #include <vespa/messagebus/routing/hop.h> #include <vespa/messagebus/routing/iroutingpolicy.h> -#include <vespa/vespalib/util/sync.h> #include <map> +#include <mutex> namespace documentapi { @@ -25,7 +25,7 @@ private: CacheEntry(); }; - vespalib::Lock _lock; + std::mutex _lock; std::map<string, CacheEntry> _cache; /** diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp index 7e324468ae5..375cdc23ba2 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp @@ -64,7 +64,7 @@ SubsetServicePolicy::getRecipient(mbus::RoutingContext &ctx) { mbus::Hop hop; if (_subsetSize > 0) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); CacheEntry &entry = update(ctx); if (!entry._recipients.empty()) { if (++entry._offset >= entry._recipients.size()) { diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.h index bf44afa318f..a6c2e0d6cae 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.h @@ -4,9 +4,8 @@ #include <vespa/documentapi/common.h> #include <vespa/messagebus/routing/hop.h> #include <vespa/messagebus/routing/iroutingpolicy.h> -#include <vespa/vespalib/util/sync.h> -#include <vector> #include <map> +#include <mutex> namespace documentapi { @@ -26,8 +25,8 @@ private: CacheEntry(); }; - vespalib::Lock _lock; - uint32_t _subsetSize; + std::mutex _lock; + uint32_t _subsetSize; std::map<string, CacheEntry> _cache; /** diff --git a/logd/src/tests/watcher/watcher_test.cpp b/logd/src/tests/watcher/watcher_test.cpp index 7e7585f9209..f74564b23f4 100644 --- a/logd/src/tests/watcher/watcher_test.cpp +++ b/logd/src/tests/watcher/watcher_test.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/gtest/gtest.h> #include <logd/config_subscriber.h> +#include <vespa/config/common/configcontext.h> #include <logd/watcher.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/threadstackexecutor.h> diff --git a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp index 1d492cb558f..533e8881d27 100644 --- a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp +++ b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp @@ -7,6 +7,7 @@ #include <vespa/config-rank-profiles.h> #include <vespa/config/config.h> #include <vespa/config/helper/legacy.h> +#include <vespa/config/common/configcontext.h> #include <vespa/config/common/exceptions.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value_cache/constant_value.h> @@ -186,7 +187,7 @@ App::Main() bool ok = false; try { - IConfigContext::SP ctx(new ConfigContext(*config::legacyConfigId2Spec(configid))); + auto ctx = std::make_shared<ConfigContext>(*config::legacyConfigId2Spec(configid)); vespalib::string cfgId(config::legacyConfigId2ConfigId(configid)); ConfigSubscriber subscriber(ctx); ConfigHandle<VerifyRanksetupConfig>::UP myHandle = subscriber.subscribe<VerifyRanksetupConfig>(cfgId); diff --git a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp index 585a493559d..dc2dca4d9c8 100644 --- a/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp +++ b/searchcore/src/apps/vespa-feed-bm/vespa_feed_bm.cpp @@ -24,6 +24,7 @@ #include <vespa/config-summary.h> #include <vespa/config-summarymap.h> #include <vespa/config-upgrading.h> +#include <vespa/config/common/configcontext.h> #include <vespa/document/datatype/documenttype.h> #include <vespa/document/fieldvalue/intfieldvalue.h> #include <vespa/document/repo/configbuilder.h> diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index 1e64a8f4ecb..93fe2f0ae24 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -14,6 +14,7 @@ #include <vespa/fileacquirer/config-filedistributorrpc.h> #include <vespa/vespalib/util/varholder.h> #include <vespa/vespalib/testkit/testapp.h> +#include <vespa/config/common/configcontext.h> #include <vespa/config-bucketspaces.h> #include <vespa/config-attributes.h> #include <vespa/config-imported-fields.h> @@ -73,7 +74,7 @@ struct ConfigTestFixture { bucketspacesBuilder(), dbConfig(), set(), - context(new ConfigContext(set)), + context(std::make_shared<ConfigContext>(set)), idcounter(-1) { set.addBuilder(configId, &protonBuilder); diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp index c8b701e82f8..e842e3cdc41 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp @@ -9,6 +9,7 @@ #include <vespa/config-rank-profiles.h> #include <vespa/config-summarymap.h> #include <vespa/config/file_acquirer/file_acquirer.h> +#include <vespa/config/common/configcontext.h> #include <vespa/config/helper/legacy.h> #include <vespa/config-attributes.h> #include <vespa/config-indexschema.h> diff --git a/slobrok/src/tests/configure/configure.cpp b/slobrok/src/tests/configure/configure.cpp index aa9826045ef..0e5b68053c8 100644 --- a/slobrok/src/tests/configure/configure.cpp +++ b/slobrok/src/tests/configure/configure.cpp @@ -5,11 +5,11 @@ #include <vespa/slobrok/sbregister.h> #include <vespa/slobrok/server/slobrokserver.h> #include <vespa/config/config.h> +#include <vespa/config/common/configcontext.h> #include <vespa/config-slobroks.h> #include <vespa/fnet/transport.h> #include <vespa/fnet/frt/supervisor.h> #include <vespa/vespalib/util/host_name.h> -#include <sstream> #include <algorithm> #include <iostream> @@ -125,7 +125,7 @@ TEST("configure_test") { set.addBuilder("client2", &cli2Builder); set.addBuilder("client3", &cli3Builder); - config::IConfigContext::SP cfgCtx(new config::ConfigContext(set)); + auto cfgCtx = std::make_shared<config::ConfigContext>(set); ConfigShim srvConfig1(18524, "server1", cfgCtx); ConfigShim srvConfig2(18525, "server2", cfgCtx); |