summaryrefslogtreecommitdiffstats
path: root/storageframework
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-10-13 11:32:52 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-10-13 11:51:00 +0200
commitac1d8b274911cf1f71e751646ca6aed260213934 (patch)
tree6066792bd6244e8393a4fbc700d9c4f99596372b /storageframework
parent025b759b5cf0146cd0cf3f44f686eeace1b28d09 (diff)
Cleanup while looking for missing join.
Diffstat (limited to 'storageframework')
-rw-r--r--storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp48
-rw-r--r--storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h10
-rw-r--r--storageframework/src/vespa/storageframework/generic/component/component.cpp22
-rw-r--r--storageframework/src/vespa/storageframework/generic/component/component.h2
4 files changed, 32 insertions, 50 deletions
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp
index eae02c71cfb..09c805b2b85 100644
--- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp
+++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp
@@ -3,12 +3,12 @@
#include "threadpoolimpl.h"
#include "threadimpl.h"
#include <vespa/vespalib/util/exceptions.h>
+#include <thread>
+using namespace std::chrono_literals;
using vespalib::IllegalStateException;
-namespace storage {
-namespace framework {
-namespace defaultimplementation {
+namespace storage::framework::defaultimplementation {
ThreadPoolImpl::ThreadPoolImpl(Clock& clock)
: _backendThreadPool(512 * 1024),
@@ -21,11 +21,11 @@ ThreadPoolImpl::~ThreadPoolImpl()
{
vespalib::LockGuard lock(_threadVectorLock);
_stopping = true;
- for (uint32_t i=0, n=_threads.size(); i<n; ++i) {
- _threads[i]->interrupt();
+ for (ThreadImpl * thread : _threads) {
+ thread->interrupt();
}
- for (uint32_t i=0, n=_threads.size(); i<n; ++i) {
- _threads[i]->join();
+ for (ThreadImpl * thread : _threads) {
+ thread->join();
}
}
for (uint32_t i=0; true; i+=10) {
@@ -34,30 +34,25 @@ ThreadPoolImpl::~ThreadPoolImpl()
if (_threads.empty()) break;
}
if (i > 1000) {
- fprintf(stderr, "Failed to kill thread pool. Threads won't die. (And "
- "if allowing thread pool object to be deleted this "
- "will create a segfault later)\n");
+ fprintf(stderr, "Failed to kill thread pool. Threads won't die. (And if allowing thread pool object"
+ " to be deleted this will create a segfault later)\n");
abort();
}
- FastOS_Thread::Sleep(10);
+ std::this_thread::sleep_for(10ms);
}
_backendThreadPool.Close();
}
Thread::UP
-ThreadPoolImpl::startThread(Runnable& runnable,
- vespalib::stringref id,
- uint64_t waitTimeMs,
- uint64_t maxProcessTime,
- int ticksBeforeWait)
+ThreadPoolImpl::startThread(Runnable& runnable, vespalib::stringref id, uint64_t waitTimeMs,
+ uint64_t maxProcessTime, int ticksBeforeWait)
{
vespalib::LockGuard lock(_threadVectorLock);
if (_stopping) {
- throw vespalib::IllegalStateException("Threadpool is stopping", VESPA_STRLOC);
+ throw IllegalStateException("Threadpool is stopping", VESPA_STRLOC);
}
ThreadImpl* ti;
- Thread::UP t(ti = new ThreadImpl(
- *this, runnable, id, waitTimeMs, maxProcessTime, ticksBeforeWait));
+ Thread::UP t(ti = new ThreadImpl(*this, runnable, id, waitTimeMs, maxProcessTime, ticksBeforeWait));
_threads.push_back(ti);
return t;
}
@@ -66,9 +61,8 @@ void
ThreadPoolImpl::visitThreads(ThreadVisitor& visitor) const
{
vespalib::LockGuard lock(_threadVectorLock);
- for (uint32_t i=0, n=_threads.size(); i<n; ++i) {
- visitor.visitThread(_threads[i]->getId(), _threads[i]->getProperties(),
- _threads[i]->getTickData());
+ for (const ThreadImpl * thread : _threads) {
+ visitor.visitThread(thread->getId(), thread->getProperties(), thread->getTickData());
}
}
@@ -78,14 +72,12 @@ ThreadPoolImpl::unregisterThread(ThreadImpl& t)
vespalib::LockGuard lock(_threadVectorLock);
std::vector<ThreadImpl*> threads;
threads.reserve(_threads.size());
- for (uint32_t i=0, n=_threads.size(); i<n; ++i) {
- if (_threads[i] != &t) {
- threads.push_back(_threads[i]);
+ for (ThreadImpl * thread : _threads) {
+ if (thread != &t) {
+ threads.push_back(thread);
}
}
_threads.swap(threads);
}
-} // defaultimplementation
-} // framework
-} // storage
+}
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h
index 2b16836eba2..4e973c2ad20 100644
--- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h
+++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h
@@ -12,11 +12,11 @@ class ThreadImpl;
struct ThreadPoolImpl : public ThreadPool
{
- FastOS_ThreadPool _backendThreadPool;
- std::vector<ThreadImpl*> _threads;
- vespalib::Lock _threadVectorLock;
- Clock& _clock;
- bool _stopping;
+ FastOS_ThreadPool _backendThreadPool;
+ std::vector<ThreadImpl*> _threads;
+ vespalib::Lock _threadVectorLock;
+ Clock & _clock;
+ bool _stopping;
public:
ThreadPoolImpl(Clock&);
diff --git a/storageframework/src/vespa/storageframework/generic/component/component.cpp b/storageframework/src/vespa/storageframework/generic/component/component.cpp
index a35cad68b00..869df4296ef 100644
--- a/storageframework/src/vespa/storageframework/generic/component/component.cpp
+++ b/storageframework/src/vespa/storageframework/generic/component/component.cpp
@@ -33,9 +33,7 @@ Component::Component(ComponentRegister& cr, vespalib::stringref name)
cr.registerComponent(*this);
}
-Component::~Component()
-{
-}
+Component::~Component() = default;
void
Component::registerComponentStateListener(ComponentStateListener& l)
@@ -67,8 +65,7 @@ Component::registerMetricUpdateHook(MetricUpdateHook& hook, SecondTime period)
assert(_metricUpdateHook.first == 0);
_metricUpdateHook = std::make_pair(&hook, period);
if (_metricReg != 0) {
- _metricReg->registerUpdateHook(
- _name, *_metricUpdateHook.first, _metricUpdateHook.second);
+ _metricReg->registerUpdateHook(_name, *_metricUpdateHook.first, _metricUpdateHook.second);
}
}
@@ -86,8 +83,7 @@ void
Component::setMetricRegistrator(MetricRegistrator& mr) {
_metricReg = &mr;
if (_metricUpdateHook.first != 0) {
- _metricReg->registerUpdateHook(
- _name, *_metricUpdateHook.first, _metricUpdateHook.second);
+ _metricReg->registerUpdateHook(_name, *_metricUpdateHook.first, _metricUpdateHook.second);
}
if (_metric != 0) {
_metricReg->registerMetric(*_metric);
@@ -117,16 +113,10 @@ Component::getClock() const
// Helper functions for components wanting to start a single thread.
Thread::UP
-Component::startThread(Runnable& runnable,
- MilliSecTime waitTime,
- MilliSecTime maxProcessTime,
- int ticksBeforeWait)
+Component::startThread(Runnable& runnable, MilliSecTime waitTime, MilliSecTime maxProcessTime, int ticksBeforeWait)
{
- return getThreadPool().startThread(runnable,
- getName(),
- waitTime.getTime(),
- maxProcessTime.getTime(),
- ticksBeforeWait);
+ return getThreadPool().startThread(runnable, getName(), waitTime.getTime(),
+ maxProcessTime.getTime(), ticksBeforeWait);
}
void
diff --git a/storageframework/src/vespa/storageframework/generic/component/component.h b/storageframework/src/vespa/storageframework/generic/component/component.h
index 8a65d186557..b16e31290b8 100644
--- a/storageframework/src/vespa/storageframework/generic/component/component.h
+++ b/storageframework/src/vespa/storageframework/generic/component/component.h
@@ -79,7 +79,7 @@ namespace storage::framework {
class ComponentRegister;
struct ComponentStateListener {
- virtual ~ComponentStateListener() {}
+ virtual ~ComponentStateListener() = default;
virtual void onOpen() {}
virtual void onClose() {}