mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
remove mutex
This commit is contained in:
@@ -3,7 +3,6 @@ package torrstor
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
@@ -20,14 +19,10 @@ type Piece struct {
|
|||||||
accessed int64
|
accessed int64
|
||||||
buffer []byte
|
buffer []byte
|
||||||
|
|
||||||
mu sync.RWMutex
|
|
||||||
cache *Cache
|
cache *Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piece) WriteAt(b []byte, off int64) (n int, err error) {
|
func (p *Piece) WriteAt(b []byte, off int64) (n int, err error) {
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
|
|
||||||
if p.buffer == nil {
|
if p.buffer == nil {
|
||||||
go p.cache.cleanPieces()
|
go p.cache.cleanPieces()
|
||||||
p.buffer = make([]byte, p.cache.pieceLength, p.cache.pieceLength)
|
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) {
|
func (p *Piece) ReadAt(b []byte, off int64) (n int, err error) {
|
||||||
p.mu.RLock()
|
|
||||||
defer p.mu.RUnlock()
|
|
||||||
|
|
||||||
size := len(b)
|
size := len(b)
|
||||||
if size+int(off) > len(p.buffer) {
|
if size+int(off) > len(p.buffer) {
|
||||||
size = len(p.buffer) - int(off)
|
size = len(p.buffer) - int(off)
|
||||||
@@ -84,8 +76,6 @@ func (p *Piece) Completion() storage.Completion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piece) Release() {
|
func (p *Piece) Release() {
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
if p.buffer != nil {
|
if p.buffer != nil {
|
||||||
p.buffer = nil
|
p.buffer = nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user