From: YenForYang Date: Tue, 14 Sep 2021 12:11:35 +0000 (-0500) Subject: Inlineable `(*File).BytesCompleted()` (#612) X-Git-Tag: v1.32.0~61 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=57b4e78b0f04b16996dc15925e22875a2ead274c;p=btrtrc.git Inlineable `(*File).BytesCompleted()` (#612) --- diff --git a/file.go b/file.go index e2720e5a..35fe9239 100644 --- a/file.go +++ b/file.go @@ -44,13 +44,14 @@ func (f *File) Length() int64 { // Number of bytes of the entire file we have completed. This is the sum of // completed pieces, and dirtied chunks of incomplete pieces. -func (f *File) BytesCompleted() int64 { +func (f *File) BytesCompleted() (n int64) { f.t.cl.rLock() - defer f.t.cl.rUnlock() - return f.bytesCompleted() + n = f.bytesCompletedLocked() + f.t.cl.rUnlock() + return } -func (f *File) bytesCompleted() int64 { +func (f *File) bytesCompletedLocked() int64 { return f.length - f.bytesLeft() }