From ca9afa85353c81392ec56e1c391430d9d3333c13 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Fri, 3 May 2024 10:34:39 +0100 Subject: [PATCH] Add per piece locks --- crates/librqbit/src/torrent_state/live/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/librqbit/src/torrent_state/live/mod.rs b/crates/librqbit/src/torrent_state/live/mod.rs index 21289a6..e93801e 100644 --- a/crates/librqbit/src/torrent_state/live/mod.rs +++ b/crates/librqbit/src/torrent_state/live/mod.rs @@ -161,6 +161,8 @@ pub struct TorrentStateLive { pub(crate) files: FileStorage, + per_piece_locks: Vec>, + stats: AtomicStats, lengths: Lengths, @@ -212,6 +214,7 @@ impl TorrentStateLive { peers: Default::default(), locked: RwLock::new(TorrentStateLocked { chunks: Some(paused.chunk_tracker), + // TODO: move under per_piece_locks inflight_pieces: Default::default(), file_priorities, fatal_errors_tx: Some(fatal_errors_tx), @@ -229,6 +232,9 @@ impl TorrentStateLive { up_speed_estimator, cancellation_token, streams: paused.streams, + per_piece_locks: (0..lengths.total_pieces()) + .map(|_| RwLock::new(())) + .collect(), }); state.spawn(