change to use readers

This commit is contained in:
yourok
2024-02-24 11:04:33 +03:00
parent f2dea39405
commit fb982aa110
2 changed files with 16 additions and 1 deletions

View File

@@ -314,6 +314,21 @@ func (c *Cache) NewReader(file *torrent.File) *Reader {
return newReader(file, c)
}
func (c *Cache) GetUseReaders() int {
if c == nil {
return 0
}
c.muReaders.Lock()
defer c.muReaders.Unlock()
readers := 0
for reader := range c.readers {
if reader.isUse {
readers++
}
}
return readers
}
func (c *Cache) Readers() int {
if c == nil {
return 0

View File

@@ -267,7 +267,7 @@ func (t *Torrent) drop() {
}
func (t *Torrent) Close() bool {
if t.cache != nil && t.cache.Readers() > 0 {
if t.cache != nil && t.cache.GetUseReaders() > 0 {
return false
}
t.Stat = state.TorrentClosed