From 56b59c898b6d1b09138ba37f18975bd28866164a Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 5 Aug 2025 22:51:28 +1000 Subject: [PATCH] Pedantic optimization of Torrent.AllowDataDownload and AllowDataUpload --- torrent.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/torrent.go b/torrent.go index fdec3460..58e078f2 100644 --- a/torrent.go +++ b/torrent.go @@ -2994,7 +2994,11 @@ func (t *Torrent) disallowDataDownloadLocked() { func (t *Torrent) AllowDataDownload() { t.cl.lock() defer t.cl.unlock() - t.dataDownloadDisallowed.Clear() + // Can't move this outside the lock because other users require it to be unchanged while the + // Client lock is held? + if !t.dataDownloadDisallowed.Clear() { + return + } t.iterPeers(func(p *Peer) { p.onNeedUpdateRequests("allow data download") }) @@ -3004,6 +3008,9 @@ func (t *Torrent) AllowDataDownload() { func (t *Torrent) AllowDataUpload() { t.cl.lock() defer t.cl.unlock() + if !t.dataUploadDisallowed { + return + } t.dataUploadDisallowed = false t.iterPeers(func(p *Peer) { p.onNeedUpdateRequests("allow data upload") -- 2.51.0