From: Ian Lynagh Date: Fri, 10 Apr 2009 16:40:13 +0000 (+0000) Subject: Fix QSem and QSemN: Initial amount must be non-negative X-Git-Tag: 2009-06-25~39 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=f779a4eeb052cfbe9eeaffd1366c8a4ff3b25703;p=ghc-base.git Fix QSem and QSemN: Initial amount must be non-negative --- diff --git a/Control/Concurrent/QSem.hs b/Control/Concurrent/QSem.hs index 87f5543..d069b89 100644 --- a/Control/Concurrent/QSem.hs +++ b/Control/Concurrent/QSem.hs @@ -41,9 +41,11 @@ INSTANCE_TYPEABLE0(QSem,qSemTc,"QSem") -- |Build a new 'QSem' newQSem :: Int -> IO QSem -newQSem initial = do - sem <- newMVar (initial, []) - return (QSem sem) +newQSem initial = + if initial < 0 + then fail "newQSem: Initial quantity must be non-negative" + else do sem <- newMVar (initial, []) + return (QSem sem) -- |Wait for a unit to become available waitQSem :: QSem -> IO () diff --git a/Control/Concurrent/QSemN.hs b/Control/Concurrent/QSemN.hs index 014a72c..7ee6142 100644 --- a/Control/Concurrent/QSemN.hs +++ b/Control/Concurrent/QSemN.hs @@ -35,10 +35,12 @@ newtype QSemN = QSemN (MVar (Int,[(Int,MVar ())])) INSTANCE_TYPEABLE0(QSemN,qSemNTc,"QSemN") -- |Build a new 'QSemN' with a supplied initial quantity. -newQSemN :: Int -> IO QSemN -newQSemN initial = do - sem <- newMVar (initial, []) - return (QSemN sem) +newQSemN :: Int -> IO QSemN +newQSemN initial = + if initial < 0 + then fail "newQSemN: Initial quantity must be non-negative" + else do sem <- newMVar (initial, []) + return (QSemN sem) -- |Wait for the specified quantity to become available waitQSemN :: QSemN -> Int -> IO ()