Avoid dispatching multiple fetch pack threads

This commit is contained in:
Spec
2018-04-04 20:36:32 +08:00
committed by Nik Bougalis
parent b0092aee24
commit 4dcb3c9199
2 changed files with 12 additions and 7 deletions

View File

@@ -337,6 +337,8 @@ private:
int mPathFindThread {0}; // Pathfinder jobs dispatched int mPathFindThread {0}; // Pathfinder jobs dispatched
bool mPathFindNewRequest {false}; bool mPathFindNewRequest {false};
std::atomic_flag mGotFetchPackThread = ATOMIC_FLAG_INIT; // GotFetchPack jobs dispatched
std::atomic <std::uint32_t> mPubLedgerClose {0}; std::atomic <std::uint32_t> mPubLedgerClose {0};
std::atomic <LedgerIndex> mPubLedgerSeq {0}; std::atomic <LedgerIndex> mPubLedgerSeq {0};
std::atomic <std::uint32_t> mValidLedgerSign {0}; std::atomic <std::uint32_t> mValidLedgerSign {0};

View File

@@ -1790,13 +1790,16 @@ LedgerMaster::gotFetchPack (
bool progress, bool progress,
std::uint32_t seq) std::uint32_t seq)
{ {
// FIXME: Calling this function more than once will result in if (!mGotFetchPackThread.test_and_set(std::memory_order_acquire))
// 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",
app_.getJobQueue().addJob ( [&] (Job&)
jtLEDGER_DATA, "gotFetchPack", {
[&] (Job&) { app_.getInboundLedgers().gotFetchPack(); }); app_.getInboundLedgers().gotFetchPack();
mGotFetchPackThread.clear(std::memory_order_release);
});
}
} }
void void