module UnliftIO.QSem
( QSem
, newQSem
, waitQSem
, signalQSem
, withQSem
) where
import Control.Concurrent.QSem (QSem)
import Control.Monad.IO.Unlift
import UnliftIO.Exception
import qualified Control.Concurrent.QSem as Q
newQSem :: MonadIO m => Int -> m QSem
newQSem :: forall (m :: * -> *). MonadIO m => Int -> m QSem
newQSem = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO QSem
Q.newQSem
waitQSem :: MonadIO m => QSem -> m ()
waitQSem :: forall (m :: * -> *). MonadIO m => QSem -> m ()
waitQSem = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. QSem -> IO ()
Q.waitQSem
signalQSem :: MonadIO m => QSem -> m ()
signalQSem :: forall (m :: * -> *). MonadIO m => QSem -> m ()
signalQSem = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. QSem -> IO ()
Q.signalQSem
{-# INLINE withQSem #-}
withQSem :: MonadUnliftIO m => QSem -> m a -> m a
withQSem :: forall (m :: * -> *) a. MonadUnliftIO m => QSem -> m a -> m a
withQSem QSem
x m a
io = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
forall (m :: * -> *) a b c.
MonadUnliftIO m =>
m a -> m b -> m c -> m c
bracket_ (forall (m :: * -> *). MonadIO m => QSem -> m ()
waitQSem QSem
x) (forall (m :: * -> *). MonadIO m => QSem -> m ()
signalQSem QSem
x) (forall a. m a -> IO a
run m a
io)