]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Torrent.BytesCompleted was racy
authorMatt Joiner <anacrolix@gmail.com>
Tue, 21 Jul 2015 12:54:02 +0000 (22:54 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 21 Jul 2015 12:54:02 +0000 (22:54 +1000)
client.go
t.go

index aaa2ee4da7e9c19e49e894f9b668aa2e4ecb4b47..8621d16425bb65a0adab5e1f1a65867fd95bfff0 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1979,7 +1979,7 @@ func (t *torrent) addTrackers(announceList [][]string) {
 }
 
 // Don't call this before the info is available.
-func (t *torrent) BytesCompleted() int64 {
+func (t *torrent) bytesCompleted() int64 {
        if !t.haveInfo() {
                return 0
        }
diff --git a/t.go b/t.go
index 419258600a6ca1aedd800dd809c147950a877e6a..8a561661e2198208eaeb601e3b1a4fc82d790aeb 100644 (file)
--- a/t.go
+++ b/t.go
@@ -52,3 +52,9 @@ func (t Torrent) Drop() {
        t.cl.dropTorrent(t.InfoHash)
        t.cl.mu.Unlock()
 }
+
+func (t Torrent) BytesCompleted() int64 {
+       t.cl.mu.RLock()
+       defer t.cl.mu.RUnlock()
+       return t.bytesCompleted()
+}