Skip to content

Commit

Permalink
Avoid dispatching multiple fetch pack threads
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveULin authored and nbougalis committed Sep 30, 2018
1 parent b0092ae commit 4dcb3c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/ripple/app/ledger/LedgerMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ class LedgerMaster
int mPathFindThread {0}; // Pathfinder jobs dispatched
bool mPathFindNewRequest {false};

std::atomic_flag mGotFetchPackThread = ATOMIC_FLAG_INIT; // GotFetchPack jobs dispatched

std::atomic <std::uint32_t> mPubLedgerClose {0};
std::atomic <LedgerIndex> mPubLedgerSeq {0};
std::atomic <std::uint32_t> mValidLedgerSign {0};
Expand Down
17 changes: 10 additions & 7 deletions src/ripple/app/ledger/impl/LedgerMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,13 +1790,16 @@ LedgerMaster::gotFetchPack (
bool progress,
std::uint32_t seq)
{
// FIXME: Calling this function more than once will result in
// InboundLedgers::gotFetchPack being called more than once
// which is expensive. A flag should track whether we've already dispatched

app_.getJobQueue().addJob (
jtLEDGER_DATA, "gotFetchPack",
[&] (Job&) { app_.getInboundLedgers().gotFetchPack(); });
if (!mGotFetchPackThread.test_and_set(std::memory_order_acquire))
{
app_.getJobQueue().addJob (
jtLEDGER_DATA, "gotFetchPack",
[&] (Job&)
{
app_.getInboundLedgers().gotFetchPack();
mGotFetchPackThread.clear(std::memory_order_release);
});
}
}

void
Expand Down

0 comments on commit 4dcb3c9

Please sign in to comment.