Skip to content

Commit

Permalink
fix races
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Jul 14, 2024
1 parent a6ac7dc commit 854a6de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions piece.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func (p *Piece) VerifyData() {
// log.Print("done")
}

func (p *Piece) queuedForHash(lock bool) bool {
return p.t.pieceQueuedForHash(p.index, lock)
func (p *Piece) queuedForHash(lockTorrent bool) bool {
return p.t.pieceQueuedForHash(p.index, lockTorrent)
}

func (p *Piece) torrentBeginOffset(lock bool) int64 {
Expand Down
7 changes: 4 additions & 3 deletions t.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ func (t *Torrent) Seeding() (ret bool) {
// Clobbers the torrent display name if metainfo is unavailable.
// The display name is used as the torrent name while the metainfo is unavailable.
func (t *Torrent) SetDisplayName(dn string) {
if !t.haveInfo(true) {
t.mu.Lock()
t.imu.Lock()
defer t.imu.Unlock()

if !t.haveInfo(false) {
t.displayName = dn
t.mu.Unlock()
}
}

Expand Down
6 changes: 5 additions & 1 deletion torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,15 @@ func (t *Torrent) pieceState(index pieceIndex, lock bool) (ret PieceState) {

p := &t.pieces[index]
ret.Priority = t.piecePriority(index, false)
ret.Completion = p.completion(true, false)
ret.QueuedForHash = p.queuedForHash(false)

p.mu.RLock()
ret.Completion = p.completion(false, false)
ret.Hashing = p.hashing
ret.Checking = ret.QueuedForHash || ret.Hashing
ret.Marking = p.marking
p.mu.RUnlock()

if !ret.Complete && t.piecePartiallyDownloaded(index, false) {
ret.Partial = true
}
Expand Down

0 comments on commit 854a6de

Please sign in to comment.