Graphics.Vty.UnicodeWidthTable.Install: use withMVar to avoid boilerplate

This commit is contained in:
Jonathan Daugherty 2020-03-09 13:49:11 -07:00
parent 0d2226cb1a
commit ab10b97e31

View File

@ -9,7 +9,8 @@ where
import Control.Monad (when, forM_)
import qualified Control.Exception as E
import Control.Concurrent.MVar (MVar, newMVar, takeMVar, putMVar)
import GHC.Conc.Sync (withMVar)
import Control.Concurrent.MVar (MVar, newMVar)
import Data.Word (Word8, Word32)
#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup ((<>))
@ -31,14 +32,7 @@ isCustomTableReady :: IO Bool
isCustomTableReady = withInstallLock $ (== 1) <$> c_isCustomTableReady
withInstallLock :: IO a -> IO a
withInstallLock act =
E.bracket takeInstallLock (const releaseInstallLock) $ const act
takeInstallLock :: IO ()
takeInstallLock = takeMVar installLock
releaseInstallLock :: IO ()
releaseInstallLock = putMVar installLock ()
withInstallLock act = withMVar installLock $ const act
-- This is the size of the allocated custom character width table, in
-- character slots. It's important that this be large enough to hold all