remove reader mutex for test

This commit is contained in:
YouROK
2020-12-30 10:18:17 +03:00
parent 1684b9fddd
commit ac4efa8a86

View File

@@ -1,8 +1,8 @@
package torrstor
import (
sync "github.com/sasha-s/go-deadlock"
"io"
"sync"
"github.com/anacrolix/torrent"
"server/log"
@@ -16,7 +16,7 @@ type Reader struct {
cache *Cache
isClosed bool
mu sync.Mutex
// mu sync.Mutex
///Preload
muPreload sync.Mutex
@@ -37,8 +37,8 @@ func newReader(file *torrent.File, cache *Cache) *Reader {
}
func (r *Reader) Seek(offset int64, whence int) (n int64, err error) {
r.mu.Lock()
defer r.mu.Unlock()
// r.mu.Lock()
// defer r.mu.Unlock()
if r.isClosed {
return 0, io.EOF
}
@@ -56,8 +56,6 @@ func (r *Reader) Seek(offset int64, whence int) (n int64, err error) {
}
func (r *Reader) Read(p []byte) (n int, err error) {
r.mu.Lock()
defer r.mu.Unlock()
err = io.EOF
if r.isClosed {
return
@@ -73,8 +71,8 @@ func (r *Reader) Read(p []byte) (n int, err error) {
}
func (r *Reader) SetReadahead(length int64) {
r.mu.Lock()
defer r.mu.Unlock()
// r.mu.Lock()
// defer r.mu.Unlock()
r.Reader.SetReadahead(length)
r.readahead = length
}
@@ -91,12 +89,12 @@ func (r *Reader) Close() {
// file reader close in gotorrent
// this struct close in cache
// TODO провверить как будут закрываться ридеры
r.mu.Lock()
// r.mu.Lock()
r.isClosed = true
if len(r.file.Torrent().Files()) > 0 {
r.Reader.Close()
}
r.mu.Unlock()
// r.mu.Unlock()
go r.cache.getRemPieces()
}