From 15850b52f581df3cecd53487c695496fc6e14b07 Mon Sep 17 00:00:00 2001 From: Miguel Portilla Date: Fri, 6 Mar 2020 15:40:22 -0500 Subject: [PATCH] [FOLD] Stop taskQueue at shutdown --- src/ripple/nodestore/impl/DatabaseShardImp.cpp | 16 ++++++++-------- src/ripple/nodestore/impl/TaskQueue.h | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ripple/nodestore/impl/DatabaseShardImp.cpp b/src/ripple/nodestore/impl/DatabaseShardImp.cpp index 86c8d96f2bb..edcc0b3c7a2 100644 --- a/src/ripple/nodestore/impl/DatabaseShardImp.cpp +++ b/src/ripple/nodestore/impl/DatabaseShardImp.cpp @@ -59,13 +59,7 @@ DatabaseShardImp::DatabaseShardImp( DatabaseShardImp::~DatabaseShardImp() { - if (!isStopping()) - onStop(); - - // Close backend databases before destroying the context - std::lock_guard lock(mutex_); - shards_.clear(); - ctx_.reset(); + onStop(); } bool @@ -660,14 +654,20 @@ DatabaseShardImp::validate() void DatabaseShardImp::onStop() { + Database::onStop(); + { std::lock_guard lock(mutex_); + + // Notify and destroy shards for (auto const& e : shards_) if (e.second.shard) e.second.shard->stop(); + shards_.clear(); } - Database::onStop(); + // Stop queued tasks + taskQueue_->pause(); } void diff --git a/src/ripple/nodestore/impl/TaskQueue.h b/src/ripple/nodestore/impl/TaskQueue.h index 309a418aa81..2a7f74d944e 100644 --- a/src/ripple/nodestore/impl/TaskQueue.h +++ b/src/ripple/nodestore/impl/TaskQueue.h @@ -40,6 +40,9 @@ class TaskQueue : private Workers::Callback void addTask(std::function task); + void + pause() {workers_.pauseAllThreadsAndWait();} + private: std::mutex mutex_; Workers workers_;