forked from TrueCloudLab/restic
bloblru: move defer outside critical section
This commit is contained in:
parent
0ad0b7ca7c
commit
21ce03cff2
1 changed files with 6 additions and 6 deletions
|
@ -100,7 +100,13 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by
|
||||||
waitForResult, isDownloading := c.inProgress[id]
|
waitForResult, isDownloading := c.inProgress[id]
|
||||||
if !isDownloading {
|
if !isDownloading {
|
||||||
c.inProgress[id] = finish
|
c.inProgress[id] = finish
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
|
||||||
|
if isDownloading {
|
||||||
|
// wait for result of parallel download
|
||||||
|
<-waitForResult
|
||||||
|
} else {
|
||||||
// remove progress channel once finished here
|
// remove progress channel once finished here
|
||||||
defer func() {
|
defer func() {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
|
@ -109,12 +115,6 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by
|
||||||
close(finish)
|
close(finish)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
c.mu.Unlock()
|
|
||||||
|
|
||||||
if isDownloading {
|
|
||||||
// wait for result of parallel download
|
|
||||||
<-waitForResult
|
|
||||||
}
|
|
||||||
|
|
||||||
// try again. This is necessary independent of whether isDownloading is true or not.
|
// try again. This is necessary independent of whether isDownloading is true or not.
|
||||||
// The calls to `c.Get()` and checking/adding the entry in `c.inProgress` are not atomic,
|
// The calls to `c.Get()` and checking/adding the entry in `c.inProgress` are not atomic,
|
||||||
|
|
Loading…
Reference in a new issue