Remove reader.opMu

https://github.com/anacrolix/torrent/issues/553
This commit is contained in:
Matt Joiner 2021-09-10 20:58:11 +10:00
parent 35064425eb
commit 1ef51e7840
1 changed files with 1 additions and 11 deletions

View File

@ -36,8 +36,6 @@ type reader struct {
responsive bool responsive bool
// Adjust the read/seek window to handle Readers locked to File extents and the like. // Adjust the read/seek window to handle Readers locked to File extents and the like.
offset, length int64 offset, length int64
// Ensure operations that change the position are exclusive, like Read() and Seek().
opMu sync.Mutex
// Required when modifying pos and readahead, or reading them without opMu. // Required when modifying pos and readahead, or reading them without opMu.
mu sync.Locker mu sync.Locker
@ -71,11 +69,9 @@ func (r *reader) SetNonResponsive() {
func (r *reader) SetReadahead(readahead int64) { func (r *reader) SetReadahead(readahead int64) {
r.mu.Lock() r.mu.Lock()
defer r.mu.Unlock()
r.readahead = readahead r.readahead = readahead
r.readaheadFunc = nil r.readaheadFunc = nil
r.mu.Unlock()
r.t.cl.lock()
defer r.t.cl.unlock()
r.posChanged() r.posChanged()
} }
@ -131,10 +127,6 @@ func (r *reader) Read(b []byte) (n int, err error) {
} }
func (r *reader) ReadContext(ctx context.Context, b []byte) (n int, err error) { func (r *reader) ReadContext(ctx context.Context, b []byte) (n int, err error) {
// Hmmm, if a Read gets stuck, this means you can't change position for other purposes. That
// seems reasonable, but unusual.
r.opMu.Lock()
defer r.opMu.Unlock()
if len(b) > 0 { if len(b) > 0 {
r.reading = true r.reading = true
// TODO: Rework reader piece priorities so we don't have to push updates in to the Client // TODO: Rework reader piece priorities so we don't have to push updates in to the Client
@ -272,8 +264,6 @@ func (r *reader) posChanged() {
} }
func (r *reader) Seek(off int64, whence int) (newPos int64, err error) { func (r *reader) Seek(off int64, whence int) (newPos int64, err error) {
r.opMu.Lock()
defer r.opMu.Unlock()
r.mu.Lock() r.mu.Lock()
defer r.mu.Unlock() defer r.mu.Unlock()
newPos, err = func() (int64, error) { newPos, err = func() (int64, error) {