aboutsummaryrefslogtreecommitdiffstats
path: root/filedistribution/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-13 13:57:20 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-09-14 09:16:52 +0000
commitde769896fbfae460967f89b51d65c3045f993c7a (patch)
tree7ce55415510617b2e1f17c5d9a43ecf4fecb2a46 /filedistribution/src
parent50bdb79f367b2da94864a0611b5b75c923dfba43 (diff)
boost::thread -> std::thread
Diffstat (limited to 'filedistribution/src')
-rw-r--r--filedistribution/src/vespa/filedistribution/common/componentsdeleter.cpp27
-rw-r--r--filedistribution/src/vespa/filedistribution/common/componentsdeleter.h11
-rw-r--r--filedistribution/src/vespa/filedistribution/common/concurrentqueue.h4
3 files changed, 28 insertions, 14 deletions
diff --git a/filedistribution/src/vespa/filedistribution/common/componentsdeleter.cpp b/filedistribution/src/vespa/filedistribution/common/componentsdeleter.cpp
index 0812b65304e..c184f5e1ae7 100644
--- a/filedistribution/src/vespa/filedistribution/common/componentsdeleter.cpp
+++ b/filedistribution/src/vespa/filedistribution/common/componentsdeleter.cpp
@@ -23,25 +23,21 @@ struct ComponentsDeleter::Worker {
void
ComponentsDeleter::Worker::operator()()
{
- while (!boost::this_thread::interruption_requested()) {
- try {
- CallDeleteFun deleteFun = _parent._deleteRequests.pop();
- boost::this_thread::disable_interruption di;
- deleteFun();
- } catch(const std::exception& e) {
- LOG(error, e.what());
- }
+ while ( ! _parent.allComponentsDeleted() ) {
+ CallDeleteFun deleteFun = _parent._deleteRequests.pop();
+ deleteFun();
}
}
-ComponentsDeleter::ComponentsDeleter()
- :_deleterThread(Worker(this))
+ComponentsDeleter::ComponentsDeleter() :
+ _closed(false),
+ _deleterThread(Worker(this))
{}
ComponentsDeleter::~ComponentsDeleter()
{
+ close();
waitForAllComponentsDeleted();
- _deleterThread.interrupt();
_deleterThread.join();
}
@@ -60,12 +56,19 @@ ComponentsDeleter::waitForAllComponentsDeleted()
if (!allComponentsDeleted())
kill(getpid(), SIGKILL);
}
+
+void
+ComponentsDeleter::close()
+{
+ LockGuard guard(_trackedComponentsMutex);
+ _closed = true;
+}
bool
ComponentsDeleter::allComponentsDeleted()
{
LockGuard guard(_trackedComponentsMutex);
- return _trackedComponents.empty();
+ return _trackedComponents.empty() && _deleteRequests.empty();
}
void
diff --git a/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h b/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h
index 41bea2ff3bc..885f063cc54 100644
--- a/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h
+++ b/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h
@@ -31,8 +31,8 @@ class ComponentsDeleter {
typedef boost::function<void (void)> CallDeleteFun;
ConcurrentQueue<CallDeleteFun> _deleteRequests;
-
- boost::thread _deleterThread;
+ bool _closed;
+ std::thread _deleterThread;
void removeFromTrackedComponents(void* component);
@@ -50,6 +50,7 @@ class ComponentsDeleter {
void waitForAllComponentsDeleted();
bool allComponentsDeleted();
void logNotDeletedComponents();
+ void close();
public:
ComponentsDeleter(const ComponentsDeleter &) = delete;
ComponentsDeleter & operator = (const ComponentsDeleter &) = delete;
@@ -64,6 +65,9 @@ class ComponentsDeleter {
template <class T>
boost::shared_ptr<T> track_boost(T* t) {
LockGuard guard(_trackedComponentsMutex);
+ if (_closed) {
+ return boost::shared_ptr<T>(t);
+ }
_trackedComponents[t] = typeid(t).name();
return boost::shared_ptr<T>(t, std::bind(&ComponentsDeleter::requestDelete<T>, this, t));
@@ -72,6 +76,9 @@ class ComponentsDeleter {
template <class T>
std::shared_ptr<T> track(T* t) {
LockGuard guard(_trackedComponentsMutex);
+ if (_closed) {
+ return std::shared_ptr<T>(t);
+ }
_trackedComponents[t] = typeid(t).name();
return std::shared_ptr<T>(t, std::bind(&ComponentsDeleter::requestDelete<T>, this, t));
diff --git a/filedistribution/src/vespa/filedistribution/common/concurrentqueue.h b/filedistribution/src/vespa/filedistribution/common/concurrentqueue.h
index 1faac8d2c58..21b8ade0ab0 100644
--- a/filedistribution/src/vespa/filedistribution/common/concurrentqueue.h
+++ b/filedistribution/src/vespa/filedistribution/common/concurrentqueue.h
@@ -46,6 +46,10 @@ public:
_queue.pop();
}
}
+ bool empty() {
+ UniqueLock guard(_queueMutex);
+ return _queue.empty();
+ }
};
} //namespace filedistribution