mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
refactor: add tr_torrent::do_idle_work() (#4434)
This commit is contained in:
@@ -472,7 +472,6 @@ public:
|
|||||||
uint8_t optimistic_unchoke_time_scaler = 0;
|
uint8_t optimistic_unchoke_time_scaler = 0;
|
||||||
|
|
||||||
bool is_running = false;
|
bool is_running = false;
|
||||||
bool needs_completeness_check = true;
|
|
||||||
|
|
||||||
tr_peerMgr* const manager;
|
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));
|
tr_announcerAddBytes(tor, TR_ANN_DOWN, tor->pieceSize(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bookkeeping */
|
// bookkeeping
|
||||||
s->needs_completeness_check = true;
|
tor->set_needs_completeness_check();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peerCallbackFunc(tr_peer* peer, tr_peer_event const& event, void* vs)
|
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();
|
static auto constexpr Msec = std::chrono::duration_cast<std::chrono::milliseconds>(BandwidthPeriod).count();
|
||||||
session->top_bandwidth_.allocate(Msec);
|
session->top_bandwidth_.allocate(Msec);
|
||||||
|
|
||||||
/* torrent upkeep */
|
// torrent upkeep
|
||||||
for (auto* const tor : session->torrents())
|
auto& torrents = session->torrents();
|
||||||
{
|
std::for_each(std::begin(torrents), std::end(torrents), [](auto* tor) { tor->do_idle_work(); });
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pump the queues */
|
/* pump the queues */
|
||||||
queuePulse(session, TR_UP);
|
queuePulse(session, TR_UP);
|
||||||
|
|||||||
@@ -1672,6 +1672,8 @@ void tr_torrent::recheckCompleteness()
|
|||||||
{
|
{
|
||||||
auto const lock = unique_lock();
|
auto const lock = unique_lock();
|
||||||
|
|
||||||
|
needs_completeness_check_ = false;
|
||||||
|
|
||||||
auto const new_completeness = completion.status();
|
auto const new_completeness = completion.status();
|
||||||
|
|
||||||
if (new_completeness != completeness)
|
if (new_completeness != completeness)
|
||||||
|
|||||||
@@ -769,6 +769,25 @@ public:
|
|||||||
return n_secs;
|
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_torrent_metainfo metainfo_;
|
||||||
|
|
||||||
tr_bandwidth bandwidth_;
|
tr_bandwidth bandwidth_;
|
||||||
@@ -886,10 +905,6 @@ public:
|
|||||||
bool magnetVerify = false;
|
bool magnetVerify = false;
|
||||||
|
|
||||||
private:
|
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)
|
void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted, bool is_bootstrapping)
|
||||||
{
|
{
|
||||||
auto const lock = unique_lock();
|
auto const lock = unique_lock();
|
||||||
@@ -903,6 +918,12 @@ private:
|
|||||||
recheckCompleteness();
|
recheckCompleteness();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tr_verify_state verify_state_ = TR_VERIFY_NONE;
|
||||||
|
float verify_progress_ = -1;
|
||||||
|
tr_interned_string bandwidth_group_;
|
||||||
|
|
||||||
|
bool needs_completeness_check_ = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
|||||||
Reference in New Issue
Block a user