]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Comments and reduced locking in trackerScraper.Run
authorMatt Joiner <anacrolix@gmail.com>
Wed, 15 Apr 2020 03:05:41 +0000 (13:05 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 15 Apr 2020 07:26:02 +0000 (17:26 +1000)
tracker_scraper.go

index 3d73c2553b0c36f3e0bd26d943037aeab92af602..9d0cc9e9d9b89a5107b16f06bad4b0b0690551fa 100644 (file)
@@ -142,24 +142,33 @@ func (me *trackerScraper) Run() {
                me.t.cl.unlock()
 
        wait:
+               // Make sure we don't announce for at least a minute since the last one.
                interval := ar.Interval
                if interval < time.Minute {
                        interval = time.Minute
                }
-               wantPeers := me.t.wantPeersEvent.LockedChan(me.t.cl.locker())
+
+               me.t.cl.lock()
+               wantPeers := me.t.wantPeersEvent.C()
+               closed := me.t.closed.C()
+               me.t.cl.unlock()
+
+               // If we want peers, reduce the interval to the minimum.
                select {
                case <-wantPeers:
                        if interval > time.Minute {
                                interval = time.Minute
                        }
+                       // Now we're at the minimum, don't trigger on it anymore.
                        wantPeers = nil
                default:
                }
 
                select {
-               case <-me.t.closed.LockedChan(me.t.cl.locker()):
+               case <-closed:
                        return
                case <-wantPeers:
+                       // Recalculate the interval.
                        goto wait
                case <-time.After(time.Until(ar.Completed.Add(interval))):
                }