Revert "run peerMgrPeerStats in session thread" (#5992)

This commit is contained in:
Cœur 2024-04-02 22:55:06 +02:00
parent 92519281b0
commit 90b82825b1
1 changed files with 7 additions and 15 deletions

View File

@ -1836,21 +1836,13 @@ tr_peer_stat* tr_peerMgrPeerStats(tr_torrent const* tor, size_t* setme_count)
auto* const ret = new tr_peer_stat[n];
// TODO: re-implement as a callback solution (similar to tr_sessionSetCompletenessCallback) in case present call to run_in_session_thread is causing hangs when the peers info window is displayed.
auto done_promise = std::promise<void>{};
auto done_future = done_promise.get_future();
tor->session->run_in_session_thread(
[&peers, &ret, &done_promise]()
{
auto const now = tr_time();
auto const now_msec = tr_time_msec();
std::transform(
std::begin(peers),
std::end(peers),
ret,
[&now, &now_msec](auto const* peer) { return peer_stat_helpers::get_peer_stats(peer, now, now_msec); });
done_promise.set_value();
});
done_future.wait();
auto const now = tr_time();
auto const now_msec = tr_time_msec();
std::transform(
std::begin(peers),
std::end(peers),
ret,
[&now, &now_msec](auto const* peer) { return peer_stat_helpers::get_peer_stats(peer, now, now_msec); });
*setme_count = n;
return ret;