From: Matt Joiner Date: Tue, 5 Aug 2025 12:51:28 +0000 (+1000) Subject: Pedantic optimization of Torrent.AllowDataDownload and AllowDataUpload X-Git-Tag: v1.59.0~2^2~49 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=56b59c898b6d1b09138ba37f18975bd28866164a;p=btrtrc.git Pedantic optimization of Torrent.AllowDataDownload and AllowDataUpload --- 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")