Skip to content

Commit

Permalink
[FOLD] Stop taskQueue at shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelportilla committed Mar 6, 2020
1 parent 2674ce0 commit 15850b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/ripple/nodestore/impl/DatabaseShardImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/nodestore/impl/TaskQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class TaskQueue : private Workers::Callback
void
addTask(std::function<void()> task);

void
pause() {workers_.pauseAllThreadsAndWait();}

private:
std::mutex mutex_;
Workers workers_;
Expand Down

0 comments on commit 15850b5

Please sign in to comment.