use rLock where can, part2 (#767)
This commit is contained in:
parent
67b55c222b
commit
caa9400c52
4
file.go
4
file.go
|
@ -156,9 +156,9 @@ func (f *File) SetPriority(prio piecePriority) {
|
||||||
|
|
||||||
// Returns the priority per File.SetPriority.
|
// Returns the priority per File.SetPriority.
|
||||||
func (f *File) Priority() (prio piecePriority) {
|
func (f *File) Priority() (prio piecePriority) {
|
||||||
f.t.cl.lock()
|
f.t.cl.rLock()
|
||||||
prio = f.prio
|
prio = f.prio
|
||||||
f.t.cl.unlock()
|
f.t.cl.rUnlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ func (pc *PeerConn) initMessageWriter() {
|
||||||
logger: pc.logger,
|
logger: pc.logger,
|
||||||
w: pc.w,
|
w: pc.w,
|
||||||
keepAlive: func() bool {
|
keepAlive: func() bool {
|
||||||
pc.locker().Lock()
|
pc.locker().RLock()
|
||||||
defer pc.locker().Unlock()
|
defer pc.locker().RUnlock()
|
||||||
return pc.useful()
|
return pc.useful()
|
||||||
},
|
},
|
||||||
writeBuffer: new(bytes.Buffer),
|
writeBuffer: new(bytes.Buffer),
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/time/rate"
|
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
@ -27,6 +26,7 @@ import (
|
||||||
pp "github.com/anacrolix/torrent/peer_protocol"
|
pp "github.com/anacrolix/torrent/peer_protocol"
|
||||||
request_strategy "github.com/anacrolix/torrent/request-strategy"
|
request_strategy "github.com/anacrolix/torrent/request-strategy"
|
||||||
"github.com/anacrolix/torrent/typed-roaring"
|
"github.com/anacrolix/torrent/typed-roaring"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PeerSource string
|
type PeerSource string
|
||||||
|
@ -356,8 +356,8 @@ func (cn *Peer) downloadRate() float64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cn *Peer) DownloadRate() float64 {
|
func (cn *Peer) DownloadRate() float64 {
|
||||||
cn.locker().Lock()
|
cn.locker().RLock()
|
||||||
defer cn.locker().Unlock()
|
defer cn.locker().RUnlock()
|
||||||
|
|
||||||
return cn.downloadRate()
|
return cn.downloadRate()
|
||||||
}
|
}
|
||||||
|
|
12
t.go
12
t.go
|
@ -86,8 +86,8 @@ func (t *Torrent) NumPieces() pieceIndex {
|
||||||
|
|
||||||
// Get missing bytes count for specific piece.
|
// Get missing bytes count for specific piece.
|
||||||
func (t *Torrent) PieceBytesMissing(piece int) int64 {
|
func (t *Torrent) PieceBytesMissing(piece int) int64 {
|
||||||
t.cl.lock()
|
t.cl.rLock()
|
||||||
defer t.cl.unlock()
|
defer t.cl.rUnlock()
|
||||||
|
|
||||||
return int64(t.pieces[piece].bytesLeft())
|
return int64(t.pieces[piece].bytesLeft())
|
||||||
}
|
}
|
||||||
|
@ -122,9 +122,9 @@ func (t *Torrent) SubscribePieceStateChanges() *pubsub.Subscription[PieceStateCh
|
||||||
// Returns true if the torrent is currently being seeded. This occurs when the
|
// Returns true if the torrent is currently being seeded. This occurs when the
|
||||||
// client is willing to upload without wanting anything in return.
|
// client is willing to upload without wanting anything in return.
|
||||||
func (t *Torrent) Seeding() (ret bool) {
|
func (t *Torrent) Seeding() (ret bool) {
|
||||||
t.cl.lock()
|
t.cl.rLock()
|
||||||
ret = t.seeding()
|
ret = t.seeding()
|
||||||
t.cl.unlock()
|
t.cl.rUnlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ func (t *Torrent) Length() int64 {
|
||||||
// Returns a run-time generated metainfo for the torrent that includes the
|
// Returns a run-time generated metainfo for the torrent that includes the
|
||||||
// info bytes and announce-list as currently known to the client.
|
// info bytes and announce-list as currently known to the client.
|
||||||
func (t *Torrent) Metainfo() metainfo.MetaInfo {
|
func (t *Torrent) Metainfo() metainfo.MetaInfo {
|
||||||
t.cl.lock()
|
t.cl.rLock()
|
||||||
defer t.cl.unlock()
|
defer t.cl.rUnlock()
|
||||||
return t.newMetaInfo()
|
return t.newMetaInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue