66
66
#include < QJsonDocument>
67
67
#include < QJsonObject>
68
68
#include < QJsonValue>
69
+ #include < QMutexLocker>
69
70
#include < QNetworkAddressEntry>
70
71
#include < QNetworkInterface>
71
72
#include < QRegularExpression>
@@ -1674,7 +1675,7 @@ void SessionImpl::endStartup(ResumeSessionContext *context)
1674
1675
reannounceToAllTrackers ();
1675
1676
}
1676
1677
1677
- m_wakeupCheckTimestamp = QDateTime::currentDateTime () ;
1678
+ m_wakeupCheckTimestamp = now ;
1678
1679
});
1679
1680
m_wakeupCheckTimestamp = QDateTime::currentDateTime ();
1680
1681
m_wakeupCheckTimer->start (30s);
@@ -5728,8 +5729,6 @@ void SessionImpl::readAlerts()
5728
5729
5729
5730
// Some torrents may become "finished" after different alerts handling.
5730
5731
processPendingFinishedTorrents ();
5731
-
5732
- processTrackerStatuses ();
5733
5732
}
5734
5733
5735
5734
void SessionImpl::handleAddTorrentAlert (const lt::add_torrent_alert *alert)
@@ -6405,7 +6404,12 @@ void SessionImpl::handleTrackerAlert(const lt::tracker_alert *alert)
6405
6404
if (!torrent)
6406
6405
return ;
6407
6406
6407
+ [[maybe_unused]] const QMutexLocker updatedTrackerStatusesLocker {&m_updatedTrackerStatusesMutex};
6408
+
6409
+ const auto prevSize = m_updatedTrackerStatuses.size ();
6408
6410
QMap<int , int > &updateInfo = m_updatedTrackerStatuses[torrent->nativeHandle ()][std::string (alert->tracker_url ())][alert->local_endpoint ];
6411
+ if (prevSize < m_updatedTrackerStatuses.size ())
6412
+ updateTrackerEntryStatuses (torrent->nativeHandle ());
6409
6413
6410
6414
if (alert->type () == lt::tracker_reply_alert::alert_type)
6411
6415
{
@@ -6467,17 +6471,6 @@ void SessionImpl::handleTorrentConflictAlert(const lt::torrent_conflict_alert *a
6467
6471
}
6468
6472
#endif
6469
6473
6470
- void SessionImpl::processTrackerStatuses ()
6471
- {
6472
- if (m_updatedTrackerStatuses.isEmpty ())
6473
- return ;
6474
-
6475
- for (auto it = m_updatedTrackerStatuses.cbegin (); it != m_updatedTrackerStatuses.cend (); ++it)
6476
- updateTrackerEntryStatuses (it.key (), it.value ());
6477
-
6478
- m_updatedTrackerStatuses.clear ();
6479
- }
6480
-
6481
6474
void SessionImpl::saveStatistics () const
6482
6475
{
6483
6476
if (!m_isStatisticsDirty)
@@ -6502,15 +6495,19 @@ void SessionImpl::loadStatistics()
6502
6495
m_previouslyUploaded = value[u" AlltimeUL" _s].toLongLong ();
6503
6496
}
6504
6497
6505
- void SessionImpl::updateTrackerEntryStatuses (lt::torrent_handle torrentHandle, QHash<std::string, QHash<lt::tcp::endpoint, QMap< int , int >>> updatedTrackers )
6498
+ void SessionImpl::updateTrackerEntryStatuses (lt::torrent_handle torrentHandle)
6506
6499
{
6507
- invokeAsync ([this , torrentHandle = std::move (torrentHandle), updatedTrackers = std::move (updatedTrackers) ]() mutable
6500
+ invokeAsync ([this , torrentHandle = std::move (torrentHandle)]() mutable
6508
6501
{
6509
6502
try
6510
6503
{
6511
6504
std::vector<lt::announce_entry> nativeTrackers = torrentHandle.trackers ();
6512
- invoke ([this , torrentHandle, nativeTrackers = std::move (nativeTrackers)
6513
- , updatedTrackers = std::move (updatedTrackers)]
6505
+
6506
+ QMutexLocker updatedTrackerStatusesLocker {&m_updatedTrackerStatusesMutex};
6507
+ QHash<std::string, QHash<lt::tcp::endpoint, QMap<int , int >>> updatedTrackers = m_updatedTrackerStatuses.take (torrentHandle);
6508
+ updatedTrackerStatusesLocker.unlock ();
6509
+
6510
+ invoke ([this , torrentHandle, nativeTrackers = std::move (nativeTrackers), updatedTrackers = std::move (updatedTrackers)]
6514
6511
{
6515
6512
TorrentImpl *torrent = m_torrents.value (torrentHandle.info_hash ());
6516
6513
if (!torrent || torrent->isStopped ())
@@ -6565,7 +6562,7 @@ void SessionImpl::handleRemovedTorrent(const TorrentID &torrentID, const QString
6565
6562
m_removingTorrents.erase (removingTorrentDataIter);
6566
6563
}
6567
6564
6568
- QDateTime SessionImpl::fromLTTimePoint32 (const libtorrent ::time_point32 &timePoint) const
6565
+ QDateTime SessionImpl::fromLTTimePoint32 (const lt ::time_point32 &timePoint) const
6569
6566
{
6570
6567
const auto secsSinceNow = lt::duration_cast<lt::seconds>(timePoint - m_ltNow + lt::milliseconds (500 )).count ();
6571
6568
return m_qNow.addSecs (secsSinceNow);
0 commit comments