2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-25 12:09:59 +00:00

bloblru: move defer outside critical section

This commit is contained in:
Michael Eischer 2024-05-26 12:38:20 +02:00
parent 0ad0b7ca7c
commit 21ce03cff2

View File

@ -100,7 +100,13 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by
waitForResult, isDownloading := c.inProgress[id]
if !isDownloading {
c.inProgress[id] = finish
}
c.mu.Unlock()
if isDownloading {
// wait for result of parallel download
<-waitForResult
} else {
// remove progress channel once finished here
defer func() {
c.mu.Lock()
@ -109,12 +115,6 @@ func (c *Cache) GetOrCompute(id restic.ID, compute func() ([]byte, error)) ([]by
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.
// The calls to `c.Get()` and checking/adding the entry in `c.inProgress` are not atomic,