From: Matt Joiner Date: Tue, 21 Jul 2015 12:54:02 +0000 (+1000) Subject: Torrent.BytesCompleted was racy X-Git-Tag: v1.0.0~1111 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8ce61e911de9126a078b2f2826cc2db747994ec7;p=btrtrc.git Torrent.BytesCompleted was racy --- diff --git a/client.go b/client.go index aaa2ee4d..8621d164 100644 --- 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 41925860..8a561661 100644 --- 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() +}