Reader.Close: Prefer to lock Client in public method

This commit is contained in:
Matt Joiner 2016-10-31 19:05:33 +11:00
parent df60a765a7
commit dc7428db54
2 changed files with 2 additions and 2 deletions

View File

@ -208,6 +208,8 @@ func (r *Reader) readOnceAt(b []byte, pos int64, ctxErr *error) (n int, err erro
}
func (r *Reader) Close() error {
r.t.cl.mu.Lock()
defer r.t.cl.mu.Unlock()
r.t.deleteReader(r)
r.t = nil
return nil

2
t.go
View File

@ -136,8 +136,6 @@ func (t *Torrent) addReader(r *Reader) {
}
func (t *Torrent) deleteReader(r *Reader) {
t.cl.mu.Lock()
defer t.cl.mu.Unlock()
delete(t.readers, r)
t.readersChanged()
}