fix crash when just one remote needs to be scanned
The TMVar is supposed to be left empty once the map is empty, but the code neglected to do that, so the next time takeMVar got an empty map, which is not handled since that was supposed to never happen.. Also, avoid any possibility of this crash. If an empty map somehow creeps in, just retry.
This commit is contained in:
parent
ac71ab7bd7
commit
7478872a09
1 changed files with 8 additions and 4 deletions
|
@ -26,10 +26,14 @@ newScanRemoteMap = atomically newEmptyTMVar
|
|||
getScanRemote :: ScanRemoteMap -> IO Remote
|
||||
getScanRemote v = atomically $ do
|
||||
m <- takeTMVar v
|
||||
let newest = Prelude.head $ reverse $
|
||||
map fst $ sortBy (compare `on` snd) $ M.toList m
|
||||
putTMVar v $ M.delete newest m
|
||||
return newest
|
||||
let l = reverse $ map fst $ sortBy (compare `on` snd) $ M.toList m
|
||||
case l of
|
||||
[] -> retry -- should never happen
|
||||
(newest:_) -> do
|
||||
let m' = M.delete newest m
|
||||
unless (M.null m') $
|
||||
putTMVar v m'
|
||||
return newest
|
||||
|
||||
{- Adds new remotes that need scanning to the map. -}
|
||||
addScanRemotes :: ScanRemoteMap -> [Remote] -> IO ()
|
||||
|
|
Loading…
Reference in a new issue