UnicodeWidthTable.Install: clean up lock use

This commit is contained in:
Jonathan Daugherty 2020-03-09 10:24:57 -07:00
parent 5772d6aa57
commit 84e391f56a

View File

@ -28,9 +28,11 @@ installLock = unsafePerformIO $ newMVar ()
--
-- This function is thread-safe.
isCustomTableReady :: IO Bool
isCustomTableReady =
E.bracket takeInstallLock (const releaseInstallLock) $
const $ (== 1) <$> c_isCustomTableReady
isCustomTableReady = withInstallLock $ (== 1) <$> c_isCustomTableReady
withInstallLock :: IO a -> IO a
withInstallLock act =
E.bracket takeInstallLock (const releaseInstallLock) $ const act
takeInstallLock :: IO ()
takeInstallLock = takeMVar installLock
@ -96,8 +98,7 @@ instance E.Exception TableInstallException
--
-- This function is thread-safe.
installUnicodeWidthTable :: UnicodeWidthTable -> IO ()
installUnicodeWidthTable table =
E.bracket takeInstallLock (const releaseInstallLock) $ const $ do
installUnicodeWidthTable table = withInstallLock $ do
initResult <- initCustomTable tableSize
when (initResult /= 0) $
E.throw $ TableInitFailure initResult tableSize