mirror of
https://github.com/transmission/transmission
synced 2025-03-04 10:38:13 +00:00
refactor: add tr_torrent::do_idle_work() (#4434)
This commit is contained in:
parent
32531fe5ef
commit
4549cc74a0
3 changed files with 32 additions and 24 deletions
|
@ -472,7 +472,6 @@ public:
|
|||
uint8_t optimistic_unchoke_time_scaler = 0;
|
||||
|
||||
bool is_running = false;
|
||||
bool needs_completeness_check = true;
|
||||
|
||||
tr_peerMgr* const manager;
|
||||
|
||||
|
@ -927,8 +926,8 @@ void tr_peerMgrPieceCompleted(tr_torrent* tor, tr_piece_index_t p)
|
|||
tr_announcerAddBytes(tor, TR_ANN_DOWN, tor->pieceSize(p));
|
||||
}
|
||||
|
||||
/* bookkeeping */
|
||||
s->needs_completeness_check = true;
|
||||
// bookkeeping
|
||||
tor->set_needs_completeness_check();
|
||||
}
|
||||
|
||||
static void peerCallbackFunc(tr_peer* peer, tr_peer_event const& event, void* vs)
|
||||
|
@ -2501,23 +2500,9 @@ void tr_peerMgr::bandwidthPulse()
|
|||
static auto constexpr Msec = std::chrono::duration_cast<std::chrono::milliseconds>(BandwidthPeriod).count();
|
||||
session->top_bandwidth_.allocate(Msec);
|
||||
|
||||
/* torrent upkeep */
|
||||
for (auto* const tor : session->torrents())
|
||||
{
|
||||
// run the completeness check for any torrents that need it
|
||||
if (auto& needs_check = tor->swarm->needs_completeness_check; needs_check)
|
||||
{
|
||||
needs_check = false;
|
||||
tor->recheckCompleteness();
|
||||
}
|
||||
|
||||
/* stop torrents that are ready to stop, but couldn't be stopped
|
||||
earlier during the peer-io callback call chain */
|
||||
if (tor->isStopping)
|
||||
{
|
||||
tr_torrentStop(tor);
|
||||
}
|
||||
}
|
||||
// torrent upkeep
|
||||
auto& torrents = session->torrents();
|
||||
std::for_each(std::begin(torrents), std::end(torrents), [](auto* tor) { tor->do_idle_work(); });
|
||||
|
||||
/* pump the queues */
|
||||
queuePulse(session, TR_UP);
|
||||
|
|
|
@ -1672,6 +1672,8 @@ void tr_torrent::recheckCompleteness()
|
|||
{
|
||||
auto const lock = unique_lock();
|
||||
|
||||
needs_completeness_check_ = false;
|
||||
|
||||
auto const new_completeness = completion.status();
|
||||
|
||||
if (new_completeness != completeness)
|
||||
|
|
|
@ -769,6 +769,25 @@ public:
|
|||
return n_secs;
|
||||
}
|
||||
|
||||
constexpr void set_needs_completeness_check() noexcept
|
||||
{
|
||||
needs_completeness_check_ = true;
|
||||
}
|
||||
|
||||
void do_idle_work()
|
||||
{
|
||||
if (needs_completeness_check_)
|
||||
{
|
||||
needs_completeness_check_ = false;
|
||||
recheckCompleteness();
|
||||
}
|
||||
|
||||
if (isStopping)
|
||||
{
|
||||
tr_torrentStop(this);
|
||||
}
|
||||
}
|
||||
|
||||
tr_torrent_metainfo metainfo_;
|
||||
|
||||
tr_bandwidth bandwidth_;
|
||||
|
@ -886,10 +905,6 @@ public:
|
|||
bool magnetVerify = false;
|
||||
|
||||
private:
|
||||
tr_verify_state verify_state_ = TR_VERIFY_NONE;
|
||||
float verify_progress_ = -1;
|
||||
tr_interned_string bandwidth_group_;
|
||||
|
||||
void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted, bool is_bootstrapping)
|
||||
{
|
||||
auto const lock = unique_lock();
|
||||
|
@ -903,6 +918,12 @@ private:
|
|||
recheckCompleteness();
|
||||
}
|
||||
}
|
||||
|
||||
tr_verify_state verify_state_ = TR_VERIFY_NONE;
|
||||
float verify_progress_ = -1;
|
||||
tr_interned_string bandwidth_group_;
|
||||
|
||||
bool needs_completeness_check_ = true;
|
||||
};
|
||||
|
||||
/***
|
||||
|
|
Loading…
Add table
Reference in a new issue