File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed
Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -460,6 +460,13 @@ tr_address tr_session::bind_address(tr_address_type type) const noexcept
460460
461461// ---
462462
463+ std::unique_lock<std::recursive_mutex> tr_sessionLock (tr_session const * const session)
464+ {
465+ return session->unique_lock ();
466+ }
467+
468+ // ---
469+
463470tr_variant tr_sessionGetDefaultSettings ()
464471{
465472 auto ret = tr_variant::make_map ();
Original file line number Diff line number Diff line change 1616
1717#ifdef __cplusplus
1818#include < functional>
19+ #include < mutex>
1920#include < string>
2021#include < string_view>
2122#else
@@ -143,6 +144,8 @@ inline auto constexpr TrDefaultPeerLimitGlobal = 200U;
143144#define TR_DEFAULT_PEER_LIMIT_TORRENT_STR " 50"
144145inline auto constexpr TrDefaultPeerLimitTorrent = 50U ;
145146
147+ std::unique_lock<std::recursive_mutex> tr_sessionLock (tr_session const * session);
148+
146149/* *
147150 * Add libtransmission's default settings to the benc dictionary.
148151 *
Original file line number Diff line number Diff line change @@ -2368,16 +2368,20 @@ - (void)updateUI
23682368 BOOL anyCompleted = NO ;
23692369 BOOL anyActive = NO ;
23702370
2371- for (Torrent* torrent in self.fTorrents )
23722371 {
2373- [torrent update ];
2372+ // avoid having to wait for the same lock multiple times in the same operation
2373+ auto const lock = tr_sessionLock (self.sessionHandle );
2374+ for (Torrent* torrent in self.fTorrents )
2375+ {
2376+ [torrent update ];
23742377
2375- // pull the upload and download speeds - most consistent by using current stats
2376- dlRate += torrent.downloadRate ;
2377- ulRate += torrent.uploadRate ;
2378+ // pull the upload and download speeds - most consistent by using current stats
2379+ dlRate += torrent.downloadRate ;
2380+ ulRate += torrent.uploadRate ;
23782381
2379- anyCompleted |= torrent.finishedSeeding ;
2380- anyActive |= torrent.active && !torrent.stalled && !torrent.error ;
2382+ anyCompleted |= torrent.finishedSeeding ;
2383+ anyActive |= torrent.active && !torrent.stalled && !torrent.error ;
2384+ }
23812385 }
23822386
23832387 PowerManager.shared .shouldPreventSleep = anyActive && [self .fDefaults boolForKey: @" SleepPrevent" ];
You can’t perform that action at this time.
0 commit comments