file.go | 4 ++-- peer-conn-msg-writer.go | 4 ++-- peerconn.go | 6 +++--- t.go | 12 ++++++------ diff --git a/file.go b/file.go index 4fb4982d1a32839581046a7fe972ab46db1e6daf..ed2f5da9ced0e74c87a903d1b160a3793331701d 100644 --- a/file.go +++ b/file.go @@ -156,9 +156,9 @@ } // Returns the priority per File.SetPriority. func (f *File) Priority() (prio piecePriority) { - f.t.cl.lock() + f.t.cl.rLock() prio = f.prio - f.t.cl.unlock() + f.t.cl.rUnlock() return } diff --git a/peer-conn-msg-writer.go b/peer-conn-msg-writer.go index b30d34e07eac3f6501a0bd1126108c99c5c95d57..0dbc4ead45c4ee27c73e5edf1a3ccee9878cdb48 100644 --- a/peer-conn-msg-writer.go +++ b/peer-conn-msg-writer.go @@ -27,8 +27,8 @@ closed: &pc.closed, logger: pc.logger, w: pc.w, keepAlive: func() bool { - pc.locker().Lock() - defer pc.locker().Unlock() + pc.locker().RLock() + defer pc.locker().RUnlock() return pc.useful() }, writeBuffer: new(bytes.Buffer), diff --git a/peerconn.go b/peerconn.go index 77857d84653235a8e5b564539cd20d8af8ec17ee..4d978f07f58d12ae2a3d39f4e78075fdb17547ba 100644 --- a/peerconn.go +++ b/peerconn.go @@ -5,7 +5,6 @@ "bufio" "bytes" "errors" "fmt" - "golang.org/x/time/rate" "io" "math/rand" "net" @@ -27,6 +26,7 @@ "github.com/anacrolix/torrent/mse" pp "github.com/anacrolix/torrent/peer_protocol" request_strategy "github.com/anacrolix/torrent/request-strategy" "github.com/anacrolix/torrent/typed-roaring" + "golang.org/x/time/rate" ) type PeerSource string @@ -356,8 +356,8 @@ return float64(num) / cn.totalExpectingTime().Seconds() } func (cn *Peer) DownloadRate() float64 { - cn.locker().Lock() - defer cn.locker().Unlock() + cn.locker().RLock() + defer cn.locker().RUnlock() return cn.downloadRate() } diff --git a/t.go b/t.go index de7965dc5be2bbe0e0cd534dae2017fac6a93122..765f3cf2a66ee6688b3895a6bd428c35e5bf9945 100644 --- a/t.go +++ b/t.go @@ -86,8 +86,8 @@ } // Get missing bytes count for specific piece. func (t *Torrent) PieceBytesMissing(piece int) int64 { - t.cl.lock() - defer t.cl.unlock() + t.cl.rLock() + defer t.cl.rUnlock() return int64(t.pieces[piece].bytesLeft()) } @@ -122,9 +122,9 @@ // Returns true if the torrent is currently being seeded. This occurs when the // client is willing to upload without wanting anything in return. func (t *Torrent) Seeding() (ret bool) { - t.cl.lock() + t.cl.rLock() ret = t.seeding() - t.cl.unlock() + t.cl.rUnlock() return } @@ -153,8 +153,8 @@ // Returns a run-time generated metainfo for the torrent that includes the // info bytes and announce-list as currently known to the client. func (t *Torrent) Metainfo() metainfo.MetaInfo { - t.cl.lock() - defer t.cl.unlock() + t.cl.rLock() + defer t.cl.rUnlock() return t.newMetaInfo() }