diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-08 08:13:01 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-08 08:15:49 +0000 |
commit | 089e0ecd9d91930dbe7d000b57763f5a77e9af9d (patch) | |
tree | f8960a04093407193a702cdfd312dd1b9db9da87 /storageframework/src | |
parent | 4291a9ec03e9b5b7c23473725678b3c0785cbf91 (diff) |
Use vespalib::Lock -> std::mutex
Diffstat (limited to 'storageframework/src')
5 files changed, 29 insertions, 35 deletions
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h b/storageframework/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h index bf810d754d6..24132f710fd 100644 --- a/storageframework/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h +++ b/storageframework/src/vespa/storageframework/defaultimplementation/clock/fakeclock.h @@ -8,11 +8,9 @@ #pragma once #include <vespa/storageframework/generic/clock/clock.h> -#include <vespa/vespalib/util/sync.h> +#include <mutex> -namespace storage { -namespace framework { -namespace defaultimplementation { +namespace storage::framework::defaultimplementation { struct FakeClock : public framework::Clock { enum Mode { @@ -25,45 +23,45 @@ struct FakeClock : public framework::Clock { private: Mode _mode; framework::MicroSecTime _absoluteTime; - mutable time_t _cycleCount; - vespalib::Lock _lock; + mutable time_t _cycleCount; + mutable std::mutex _lock; public: FakeClock(Mode m = FAKE_ABSOLUTE, framework::MicroSecTime startTime = framework::MicroSecTime(1)); void setMode(Mode m) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); _mode = m; } virtual void setFakeCycleMode() { setMode(FAKE_ABSOLUTE_CYCLE); } virtual void setAbsoluteTimeInSeconds(uint32_t seconds) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); _absoluteTime = framework::MicroSecTime(seconds * uint64_t(1000000)); _cycleCount = 0; _mode = FAKE_ABSOLUTE; } virtual void setAbsoluteTimeInMicroSeconds(uint64_t usecs) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); _absoluteTime = framework::MicroSecTime(usecs); _cycleCount = 0; _mode = FAKE_ABSOLUTE; } virtual void addMilliSecondsToTime(uint64_t ms) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); _absoluteTime += framework::MicroSecTime(ms * 1000); } virtual void addSecondsToTime(uint32_t nr) { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); _absoluteTime += framework::MicroSecTime(nr * uint64_t(1000000)); } framework::MicroSecTime getTimeInMicros() const override { - vespalib::LockGuard guard(_lock); + std::lock_guard guard(_lock); if (_mode == FAKE_ABSOLUTE) return _absoluteTime; return _absoluteTime + framework::MicroSecTime(1000000 * _cycleCount++); } @@ -80,7 +78,5 @@ public: } }; -} // defaultimplementation -} // framework -} // storage +} diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.cpp b/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.cpp index ad2d0df5824..e4560370a01 100644 --- a/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.cpp +++ b/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.cpp @@ -25,7 +25,7 @@ ComponentRegisterImpl::~ComponentRegisterImpl() = default; void ComponentRegisterImpl::registerComponent(ManagedComponent& mc) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); _components.push_back(&mc); if (_clock) { mc.setClock(*_clock); @@ -42,7 +42,7 @@ ComponentRegisterImpl::registerComponent(ManagedComponent& mc) void ComponentRegisterImpl::requestShutdown(vespalib::stringref reason) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); if (_shutdownListener) { _shutdownListener->requestShutdown(reason); } @@ -53,7 +53,7 @@ ComponentRegisterImpl::setMetricManager(metrics::MetricManager& mm) { std::vector<ManagedComponent*> components; { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); assert(_metricManager == nullptr); components = _components; _metricManager = &mm; @@ -70,7 +70,7 @@ ComponentRegisterImpl::setMetricManager(metrics::MetricManager& mm) void ComponentRegisterImpl::setClock(Clock& c) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); assert(_clock == nullptr); _clock = &c; for (auto* component : _components) { @@ -81,7 +81,7 @@ ComponentRegisterImpl::setClock(Clock& c) void ComponentRegisterImpl::setThreadPool(ThreadPool& tp) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); assert(_threadPool == nullptr); _threadPool = &tp; for (auto* component : _components) { @@ -92,7 +92,7 @@ ComponentRegisterImpl::setThreadPool(ThreadPool& tp) void ComponentRegisterImpl::setUpgradeFlag(UpgradeFlags flag) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); _upgradeFlag = flag; for (auto* component : _components) { component->setUpgradeFlag(_upgradeFlag); @@ -102,7 +102,7 @@ ComponentRegisterImpl::setUpgradeFlag(UpgradeFlags flag) const StatusReporter* ComponentRegisterImpl::getStatusReporter(vespalib::stringref id) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); for (auto* component : _components) { if ((component->getStatusReporter() != nullptr) && (component->getStatusReporter()->getId() == id)) @@ -117,7 +117,7 @@ std::vector<const StatusReporter*> ComponentRegisterImpl::getStatusReporters() { std::vector<const StatusReporter*> reporters; - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); for (auto* component : _components) { if (component->getStatusReporter() != nullptr) { reporters.emplace_back(component->getStatusReporter()); @@ -153,7 +153,7 @@ ComponentRegisterImpl::registerUpdateHook(vespalib::stringref name, MetricUpdateHook& hook, SecondTime period) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); auto hookPtr = std::make_unique<MetricHookWrapper>(name, hook); _metricManager->addMetricUpdateHook(*hookPtr, period.getTime()); _hooks.emplace_back(std::move(hookPtr)); @@ -168,7 +168,7 @@ ComponentRegisterImpl::getMetricManagerLock() void ComponentRegisterImpl::registerShutdownListener(ShutdownListener& listener) { - vespalib::LockGuard lock(_componentLock); + std::lock_guard lock(_componentLock); assert(_shutdownListener == nullptr); _shutdownListener = &listener; } diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.h b/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.h index b5f79313dfb..3adef5f4838 100644 --- a/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.h +++ b/storageframework/src/vespa/storageframework/defaultimplementation/component/componentregisterimpl.h @@ -21,7 +21,6 @@ #include <vespa/storageframework/generic/component/managedcomponent.h> #include <vespa/storageframework/generic/metric/metricregistrator.h> #include <vespa/storageframework/generic/status/statusreportermap.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/metrics/metricset.h> namespace metrics { @@ -43,7 +42,7 @@ class ComponentRegisterImpl : public virtual ComponentRegister, public StatusReporterMap, public MetricRegistrator { - vespalib::Lock _componentLock; + std::mutex _componentLock; std::vector<ManagedComponent*> _components; metrics::MetricSet _topMetricSet; diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp index affeae44c04..e4a1188030c 100644 --- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp +++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp @@ -21,7 +21,7 @@ ThreadPoolImpl::ThreadPoolImpl(Clock& clock) ThreadPoolImpl::~ThreadPoolImpl() { { - vespalib::LockGuard lock(_threadVectorLock); + std::lock_guard lock(_threadVectorLock); _stopping = true; for (ThreadImpl * thread : _threads) { thread->interrupt(); @@ -32,7 +32,7 @@ ThreadPoolImpl::~ThreadPoolImpl() } for (uint32_t i=0; true; i+=10) { { - vespalib::LockGuard lock(_threadVectorLock); + std::lock_guard lock(_threadVectorLock); if (_threads.empty()) break; } if (i > 1000) { @@ -49,7 +49,7 @@ Thread::UP ThreadPoolImpl::startThread(Runnable& runnable, vespalib::stringref id, uint64_t waitTimeMs, uint64_t maxProcessTime, int ticksBeforeWait) { - vespalib::LockGuard lock(_threadVectorLock); + std::lock_guard lock(_threadVectorLock); if (_stopping) { throw IllegalStateException("Threadpool is stopping", VESPA_STRLOC); } @@ -62,7 +62,7 @@ ThreadPoolImpl::startThread(Runnable& runnable, vespalib::stringref id, uint64_t void ThreadPoolImpl::visitThreads(ThreadVisitor& visitor) const { - vespalib::LockGuard lock(_threadVectorLock); + std::lock_guard lock(_threadVectorLock); for (const ThreadImpl * thread : _threads) { visitor.visitThread(thread->getId(), thread->getProperties(), thread->getTickData()); } @@ -71,7 +71,7 @@ ThreadPoolImpl::visitThreads(ThreadVisitor& visitor) const void ThreadPoolImpl::unregisterThread(ThreadImpl& t) { - vespalib::LockGuard lock(_threadVectorLock); + std::lock_guard lock(_threadVectorLock); std::vector<ThreadImpl*> threads; threads.reserve(_threads.size()); for (ThreadImpl * thread : _threads) { diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h index 4e973c2ad20..5f0ee523eff 100644 --- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h +++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h @@ -4,7 +4,6 @@ #include <vespa/storageframework/generic/thread/threadpool.h> #include <vespa/fastos/thread.h> -#include <vespa/vespalib/util/sync.h> namespace storage::framework::defaultimplementation { @@ -14,13 +13,13 @@ struct ThreadPoolImpl : public ThreadPool { FastOS_ThreadPool _backendThreadPool; std::vector<ThreadImpl*> _threads; - vespalib::Lock _threadVectorLock; + mutable std::mutex _threadVectorLock; Clock & _clock; bool _stopping; public: ThreadPoolImpl(Clock&); - ~ThreadPoolImpl(); + ~ThreadPoolImpl() override; Thread::UP startThread(Runnable&, vespalib::stringref id, uint64_t waitTimeMs, uint64_t maxProcessTime, int ticksBeforeWait) override; |