on master help sign in
Graphics.Vty.UnicodeWidthTable.Install: use withMVar to avoid boilerplate
commitab10b97e3120dcce20073708c2e4bcd8efcd19b1 authorJonathan Daugherty <cygnus@foobox.com> dateMon 9 Mar 2020, 13:49 (7 years ago) parent0d2226c
1 file changed+3−9
src/Graphics/Vty/UnicodeWidthTable/Install.hs+3−9
src/Graphics/Vty/UnicodeWidthTable/Install.hs+3−9
@@ -9,7 +9,8 @@ where
99
1010import Control.Monad (when, forM_)
1111import qualified Control.Exception as E
12−import Control.Concurrent.MVar (MVar, newMVar, takeMVar, putMVar)
12+import GHC.Conc.Sync (withMVar)
13+import Control.Concurrent.MVar (MVar, newMVar)
1314import Data.Word (Word8, Word32)
1415#if !(MIN_VERSION_base(4,11,0))
1516import Data.Semigroup ((<>))
@@ -31,14 +32,7 @@ isCustomTableReady :: IO Bool
3132isCustomTableReady = withInstallLock $ (== 1) <$> c_isCustomTableReady
3233
3334withInstallLock :: IO a -> IO a
34−withInstallLock act =
35− E.bracket takeInstallLock (const releaseInstallLock) $ const act
36−
37−takeInstallLock :: IO ()
38−takeInstallLock = takeMVar installLock
39−
40−releaseInstallLock :: IO ()
41−releaseInstallLock = putMVar installLock ()
35+withInstallLock act = withMVar installLock $ const act
4236
4337-- This is the size of the allocated custom character width table, in
4438-- character slots. It's important that this be large enough to hold all