fixupWorkerCache :: WorkerCache -> IO ()
fixupWorkerCache wc =
    do w <- atomically $ do n <- readTVar $ wc_nr_workers wc
                            if n <= cacheSize
                             then return Nothing
                             else do targ <- readTVar $ hw_prev_lru $ wc_root wc
                                     dead <-
                                         assert ("nr_workers " ++ (show n) ++ " but no workers found") (not $ hw_is_root targ) $
                                         privatiseWorker wc targ
                                     assert "dead worker on list" (not dead) $
                                         return $ Just targ
       case w of
         Just w' -> reallyKillHistoryWorker w' >> fixupWorkerCache wc
         Nothing -> return ()
fixupWorkerCache :: WorkerCache -> IO ()
fixupWorkerCache wc =
    do w <- atomically $ do n <- readTVar $ wc_nr_workers wc
                            if n <= cacheSize
                             then return Nothing
                             else do targ <- readTVar $ hw_prev_lru $ wc_root wc
                                     dead <-
                                         assert ("nr_workers " ++ (show n) ++ " but no workers found") (not $ hw_is_root targ) $
                                         privatiseWorker wc targ
                                     assert "dead worker on list" (not dead) $
                                         return $ Just targ
       case w of
         Just w' -> reallyKillHistoryWorker w' >> fixupWorkerCache wc
         Nothing -> return ()
fixupWorkerCache wc =
    do w <- atomically $ do n <- readTVar $ wc_nr_workers wc
                            if n <= cacheSize
                             then return Nothing
                             else do targ <- readTVar $ hw_prev_lru $ wc_root wc
                                     dead <-
                                         assert ("nr_workers " ++ (show n) ++ " but no workers found") (not $ hw_is_root targ) $
                                         privatiseWorker wc targ
                                     assert "dead worker on list" (not dead) $
                                         return $ Just targ
       case w of
         Just w' -> reallyKillHistoryWorker w' >> fixupWorkerCache wc
         Nothing -> return ()