]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Inlineable methods to access File piecePriority (#601)
authorYenForYang <YenForYang@users.noreply.github.com>
Mon, 13 Sep 2021 11:17:54 +0000 (06:17 -0500)
committerGitHub <noreply@github.com>
Mon, 13 Sep 2021 11:17:54 +0000 (21:17 +1000)
file.go

diff --git a/file.go b/file.go
index bd5a6999ff89e685c7a8d44f2ce573d25242c37f..e2720e5a4d0886e0e75c620ac7187a7c8a037479 100644 (file)
--- a/file.go
+++ b/file.go
@@ -146,19 +146,19 @@ func (f *File) NewReader() Reader {
 // Sets the minimum priority for pieces in the File.
 func (f *File) SetPriority(prio piecePriority) {
        f.t.cl.lock()
-       defer f.t.cl.unlock()
-       if prio == f.prio {
-               return
+       if prio != f.prio {
+               f.prio = prio
+               f.t.updatePiecePriorities(f.firstPieceIndex(), f.endPieceIndex())
        }
-       f.prio = prio
-       f.t.updatePiecePriorities(f.firstPieceIndex(), f.endPieceIndex())
+       f.t.cl.unlock()
 }
 
 // Returns the priority per File.SetPriority.
-func (f *File) Priority() piecePriority {
+func (f *File) Priority() (prio piecePriority) {
        f.t.cl.lock()
-       defer f.t.cl.unlock()
-       return f.prio
+       prio = f.prio
+       f.t.cl.unlock()
+       return
 }
 
 // Returns the index of the first piece containing data for the file.