]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Pedantic optimization of Torrent.AllowDataDownload and AllowDataUpload
authorMatt Joiner <anacrolix@gmail.com>
Tue, 5 Aug 2025 12:51:28 +0000 (22:51 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 5 Aug 2025 12:51:28 +0000 (22:51 +1000)
torrent.go

index fdec3460f29cdc2a8ff514f0b494d81bf4eb30d4..58e078f2edefa377e322f5bad6ee920b144d45ea 100644 (file)
@@ -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")