projects
/
ghc-base.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tweak docs
[ghc-base.git]
/
Control
/
Concurrent
/
QSem.hs
diff --git
a/Control/Concurrent/QSem.hs
b/Control/Concurrent/QSem.hs
index
87f5543
..
cc78470
100644
(file)
--- a/
Control/Concurrent/QSem.hs
+++ b/
Control/Concurrent/QSem.hs
@@
-39,11
+39,14
@@
newtype QSem = QSem (MVar (Int, [MVar ()]))
INSTANCE_TYPEABLE0(QSem,qSemTc,"QSem")
INSTANCE_TYPEABLE0(QSem,qSemTc,"QSem")
--- |Build a new 'QSem'
+-- |Build a new 'QSem' with a supplied initial quantity.
+-- The initial quantity must be at least 0.
newQSem :: Int -> IO 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 ()
-- |Wait for a unit to become available
waitQSem :: QSem -> IO ()