Inlineable methods to access File piecePriority (#601)

This commit is contained in:
YenForYang 2021-09-13 06:17:54 -05:00 committed by GitHub
parent 5c440e8929
commit 52e8c82999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

16
file.go
View File

@ -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.