Synchronize access to storage
This commit is contained in:
parent
72340f6ffc
commit
d77e939944
|
@ -64,6 +64,8 @@ type Torrent struct {
|
||||||
storageOpener *storage.Client
|
storageOpener *storage.Client
|
||||||
// Storage for torrent data.
|
// Storage for torrent data.
|
||||||
storage *storage.Torrent
|
storage *storage.Torrent
|
||||||
|
// Read-locked for using storage, and write-locked for Closing.
|
||||||
|
storageLock sync.RWMutex
|
||||||
|
|
||||||
metainfo metainfo.MetaInfo
|
metainfo metainfo.MetaInfo
|
||||||
|
|
||||||
|
@ -611,7 +613,9 @@ func (t *Torrent) numPiecesCompleted() (num int) {
|
||||||
func (t *Torrent) close() (err error) {
|
func (t *Torrent) close() (err error) {
|
||||||
t.closed.Set()
|
t.closed.Set()
|
||||||
if t.storage != nil {
|
if t.storage != nil {
|
||||||
|
t.storageLock.Lock()
|
||||||
t.storage.Close()
|
t.storage.Close()
|
||||||
|
t.storageLock.Unlock()
|
||||||
}
|
}
|
||||||
for conn := range t.conns {
|
for conn := range t.conns {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
@ -1547,8 +1551,10 @@ func (t *Torrent) verifyPiece(piece int) {
|
||||||
}
|
}
|
||||||
p.hashing = true
|
p.hashing = true
|
||||||
t.publishPieceChange(piece)
|
t.publishPieceChange(piece)
|
||||||
|
t.storageLock.RLock()
|
||||||
cl.mu.Unlock()
|
cl.mu.Unlock()
|
||||||
sum := t.hashPiece(piece)
|
sum := t.hashPiece(piece)
|
||||||
|
t.storageLock.RUnlock()
|
||||||
cl.mu.Lock()
|
cl.mu.Lock()
|
||||||
p.hashing = false
|
p.hashing = false
|
||||||
t.pieceHashed(piece, sum == p.hash)
|
t.pieceHashed(piece, sum == p.hash)
|
||||||
|
|
Loading…
Reference in New Issue