From: Matt Joiner Date: Fri, 26 May 2017 02:59:52 +0000 (+1000) Subject: Move File.State lock to top of function X-Git-Tag: v1.0.0~469 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=43a573d46f0ebb0a52e26fe1eb69e4525ec257eb;p=btrtrc.git Move File.State lock to top of function --- diff --git a/file.go b/file.go index f57cd7af..720e4fb5 100644 --- a/file.go +++ b/file.go @@ -54,6 +54,8 @@ type FilePieceState struct { // Returns the state of pieces in this file. func (f *File) State() (ret []FilePieceState) { + f.t.cl.mu.RLock() + defer f.t.cl.mu.RUnlock() pieceSize := int64(f.t.usualPieceSize()) off := f.offset % pieceSize remaining := f.length @@ -65,9 +67,7 @@ func (f *File) State() (ret []FilePieceState) { if len1 > remaining { len1 = remaining } - f.t.cl.mu.RLock() ps := f.t.pieceState(i) - f.t.cl.mu.RUnlock() ret = append(ret, FilePieceState{len1, ps}) off = 0 remaining -= len1