From: YenForYang Date: Mon, 13 Sep 2021 11:17:54 +0000 (-0500) Subject: Inlineable methods to access File piecePriority (#601) X-Git-Tag: v1.32.0~68 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=52e8c82999cd265fee14ed1cfc9e96b931d03654;p=btrtrc.git Inlineable methods to access File piecePriority (#601) --- diff --git a/file.go b/file.go index bd5a6999..e2720e5a 100644 --- 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.