remove mutex

This commit is contained in:
YouROK
2021-03-29 15:06:56 +03:00
parent 2b24085be2
commit d201842e73

View File

@@ -3,7 +3,6 @@ package torrstor
import (
"errors"
"io"
"sync"
"time"
"github.com/anacrolix/torrent"
@@ -20,14 +19,10 @@ type Piece struct {
accessed int64
buffer []byte
mu sync.RWMutex
cache *Cache
}
func (p *Piece) WriteAt(b []byte, off int64) (n int, err error) {
p.mu.Lock()
defer p.mu.Unlock()
if p.buffer == nil {
go p.cache.cleanPieces()
p.buffer = make([]byte, p.cache.pieceLength, p.cache.pieceLength)
@@ -39,9 +34,6 @@ func (p *Piece) WriteAt(b []byte, off int64) (n int, err error) {
}
func (p *Piece) ReadAt(b []byte, off int64) (n int, err error) {
p.mu.RLock()
defer p.mu.RUnlock()
size := len(b)
if size+int(off) > len(p.buffer) {
size = len(p.buffer) - int(off)
@@ -84,8 +76,6 @@ func (p *Piece) Completion() storage.Completion {
}
func (p *Piece) Release() {
p.mu.Lock()
defer p.mu.Unlock()
if p.buffer != nil {
p.buffer = nil
}