Torrent.BytesCompleted was racy

This commit is contained in:
Matt Joiner 2015-07-21 22:54:02 +10:00
parent 78ec88ad02
commit 8ce61e911d
2 changed files with 7 additions and 1 deletions

View File

@ -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
}

6
t.go
View File

@ -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()
}