X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Control%2FConcurrent%2FQSemN.hs;h=cfcff7f5d8c4e89794a6a4475073afffc1237782;hb=41e8fba828acbae1751628af50849f5352b27873;hp=df3fa4207b754958c8d523f71a4e66beeb2ef10f;hpb=3d4f3f4b8bc5571d3015816671457c88c0e697c3;p=ghc-base.git diff --git a/Control/Concurrent/QSemN.hs b/Control/Concurrent/QSemN.hs index df3fa42..cfcff7f 100644 --- a/Control/Concurrent/QSemN.hs +++ b/Control/Concurrent/QSemN.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + ----------------------------------------------------------------------------- -- | -- Module : Control.Concurrent.QSemN @@ -24,14 +26,14 @@ module Control.Concurrent.QSemN import Prelude import Control.Concurrent.MVar -import Control.Exception ( block ) +import Control.Exception ( mask_ ) import Data.Typeable #include "Typeable.h" -- |A 'QSemN' is a quantity semaphore, in which the available -- \"quantity\" may be signalled or waited for in arbitrary amounts. -newtype QSemN = QSemN (MVar (Int,[(Int,MVar ())])) +newtype QSemN = QSemN (MVar (Int,[(Int,MVar ())])) deriving Eq INSTANCE_TYPEABLE0(QSemN,qSemNTc,"QSemN") @@ -46,7 +48,7 @@ newQSemN initial = -- |Wait for the specified quantity to become available waitQSemN :: QSemN -> Int -> IO () -waitQSemN (QSemN sem) sz = block $ do +waitQSemN (QSemN sem) sz = mask_ $ do (avail,blocked) <- takeMVar sem -- gain ex. access let remaining = avail - sz if remaining >= 0 then @@ -60,7 +62,7 @@ waitQSemN (QSemN sem) sz = block $ do -- |Signal that a given quantity is now available from the 'QSemN'. signalQSemN :: QSemN -> Int -> IO () -signalQSemN (QSemN sem) n = block $ do +signalQSemN (QSemN sem) n = mask_ $ do (avail,blocked) <- takeMVar sem (avail',blocked') <- free (avail+n) blocked avail' `seq` putMVar sem (avail',blocked')