Skip to content

Commit

Permalink
[FOLD] Defer setting Stoppable parent
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelportilla committed Jul 17, 2019
1 parent 4ea350a commit 85da4d4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/ripple/core/Stoppable.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class Stoppable
/** Destroy the Stoppable. */
virtual ~Stoppable ();

RootStoppable& getRoot() {return m_root;}

/** Add this Stoppable to a parent. */
void addToParent(Stoppable& parent);

/** Returns `true` if the stoppable should stop. */
bool isStopping () const;

Expand Down
13 changes: 9 additions & 4 deletions src/ripple/core/impl/Stoppable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ Stoppable::Stoppable (std::string name, Stoppable& parent)
, m_root (parent.m_root)
, m_child (this)
{
// Must not have stopping parent.
assert (! parent.isStopping());

parent.m_children.push_front (&m_child);
addToParent(parent);
}

Stoppable::~Stoppable ()
{
}

void Stoppable::addToParent (Stoppable& parent)
{
// Must not have stopping parent.
assert (! parent.isStopping());

parent.m_children.push_front(&m_child);
}

bool Stoppable::isStopping() const
{
return m_root.isStopping();
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/nodestore/impl/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Database::Database(
int readThreads,
Section const& config,
beast::Journal journal)
: Stoppable(name, parent)
: Stoppable(name, parent.getRoot())
, j_(journal)
, scheduler_(scheduler)
, earliestSeq_(get<std::uint32_t>(
Expand Down
1 change: 1 addition & 0 deletions src/ripple/nodestore/impl/DatabaseNodeImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DatabaseNodeImp : public Database
, backend_(std::move(backend))
{
assert(backend_);
addToParent(parent);
}

~DatabaseNodeImp() override
Expand Down
1 change: 1 addition & 0 deletions src/ripple/nodestore/impl/DatabaseRotatingImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DatabaseRotatingImp::DatabaseRotatingImp(
fdLimit_ += writableBackend_->fdlimit();
if (archiveBackend_)
fdLimit_ += archiveBackend_->fdlimit();
addToParent(parent);
}

// Make sure to call it already locked!
Expand Down
6 changes: 4 additions & 2 deletions src/ripple/nodestore/impl/DatabaseShardImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,10 @@ make_ShardStore(
scheduler,
readThreads,
j);
if (!shardStore->init())
Throw<std::runtime_error>("shard store failed to initialize.");
if (shardStore->init())
shardStore->addToParent(parent);
else
shardStore.reset();

return shardStore;
}
Expand Down

0 comments on commit 85da4d4

Please sign in to comment.