module Control.Concurrent.Classy.QSem
(
QSem
, newQSem
, waitQSem
, signalQSem
) where
import Control.Concurrent.Classy.QSemN
import Control.Monad.Conc.Class (MonadConc)
import Control.Monad.Fail (MonadFail)
newtype QSem m = QSem (QSemN m)
newQSem :: (MonadConc m, MonadFail m) => Int -> m (QSem m)
newQSem :: forall (m :: * -> *).
(MonadConc m, MonadFail m) =>
Int -> m (QSem m)
newQSem Int
initial
| Int
initial forall a. Ord a => a -> a -> Bool
< Int
0 = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"newQSem: Initial quantity mus tbe non-negative."
| Bool
otherwise = forall (m :: * -> *). QSemN m -> QSem m
QSem forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
(MonadConc m, MonadFail m) =>
Int -> m (QSemN m)
newQSemN Int
initial
waitQSem :: MonadConc m => QSem m -> m ()
waitQSem :: forall (m :: * -> *). MonadConc m => QSem m -> m ()
waitQSem (QSem QSemN m
qSemN) = forall (m :: * -> *). MonadConc m => QSemN m -> Int -> m ()
waitQSemN QSemN m
qSemN Int
1
signalQSem :: MonadConc m => QSem m -> m ()
signalQSem :: forall (m :: * -> *). MonadConc m => QSem m -> m ()
signalQSem (QSem QSemN m
qSemN) = forall (m :: * -> *). MonadConc m => QSemN m -> Int -> m ()
signalQSemN QSemN m
qSemN Int
1