Aggressively wake Readers
This commit is contained in:
parent
b2860bad21
commit
898e878c69
1
piece.go
1
piece.go
|
@ -94,6 +94,7 @@ func (p *Piece) numDirtyChunks() (ret int) {
|
||||||
|
|
||||||
func (p *Piece) unpendChunkIndex(i int) {
|
func (p *Piece) unpendChunkIndex(i int) {
|
||||||
p.dirtyChunks.Add(i)
|
p.dirtyChunks.Add(i)
|
||||||
|
p.t.tickleReaders()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piece) pendChunkIndex(i int) {
|
func (p *Piece) pendChunkIndex(i int) {
|
||||||
|
|
|
@ -147,7 +147,7 @@ func (r *reader) ReadContext(ctx context.Context, b []byte) (n int, err error) {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
r.t.cl.mu.Lock()
|
r.t.cl.mu.Lock()
|
||||||
ctxErr = ctx.Err()
|
ctxErr = ctx.Err()
|
||||||
r.t.cl.event.Broadcast()
|
r.t.tickleReaders()
|
||||||
r.t.cl.mu.Unlock()
|
r.t.cl.mu.Unlock()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,10 @@ type Torrent struct {
|
||||||
pendingRequests map[request]int
|
pendingRequests map[request]int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Torrent) tickleReaders() {
|
||||||
|
t.cl.event.Broadcast()
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a channel that is closed when the Torrent is closed.
|
// Returns a channel that is closed when the Torrent is closed.
|
||||||
func (t *Torrent) Closed() <-chan struct{} {
|
func (t *Torrent) Closed() <-chan struct{} {
|
||||||
return t.closed.LockedChan(&t.cl.mu)
|
return t.closed.LockedChan(&t.cl.mu)
|
||||||
|
@ -672,6 +676,7 @@ func (t *Torrent) numPiecesCompleted() (num int) {
|
||||||
|
|
||||||
func (t *Torrent) close() (err error) {
|
func (t *Torrent) close() (err error) {
|
||||||
t.closed.Set()
|
t.closed.Set()
|
||||||
|
t.tickleReaders()
|
||||||
if t.storage != nil {
|
if t.storage != nil {
|
||||||
t.storageLock.Lock()
|
t.storageLock.Lock()
|
||||||
t.storage.Close()
|
t.storage.Close()
|
||||||
|
@ -1078,6 +1083,7 @@ func (t *Torrent) updatePieceCompletion(piece int) {
|
||||||
log.Fmsg("piece %d completion: %v", piece, pcu.Ok).AddValue(debugLogValue).Log(t.logger)
|
log.Fmsg("piece %d completion: %v", piece, pcu.Ok).AddValue(debugLogValue).Log(t.logger)
|
||||||
p.storageCompletionOk = pcu.Ok
|
p.storageCompletionOk = pcu.Ok
|
||||||
t.completedPieces.Set(piece, pcu.Complete)
|
t.completedPieces.Set(piece, pcu.Complete)
|
||||||
|
t.tickleReaders()
|
||||||
// log.Printf("piece %d uncached completion: %v", piece, pcu.Complete)
|
// log.Printf("piece %d uncached completion: %v", piece, pcu.Complete)
|
||||||
// log.Printf("piece %d changed: %v", piece, changed)
|
// log.Printf("piece %d changed: %v", piece, changed)
|
||||||
if changed {
|
if changed {
|
||||||
|
|
Loading…
Reference in New Issue