ConcurrentUtils 0.4.0.0 → 0.4.1.0
raw patch · 2 files changed
+11/−11 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- ConcurrentUtils.cabal +4/−4
- Control/CUtils/Channel.hs +7/−7
ConcurrentUtils.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: ConcurrentUtils -version: 0.4.0.0 +version: 0.4.1.0 synopsis: Concurrent utilities -- description: homepage: http://alkalisoftware.net @@ -16,6 +16,6 @@ cabal-version: >=1.8 library - exposed-modules: Control.CUtils.Split, Control.CUtils.Processes, Control.CUtils.NetChan, Control.CUtils.FChan, Control.CUtils.Deadlock, Control.CUtils.DataParallel, Control.CUtils.Conc, Control.CUtils.Channel, Control.CUtils.AList - -- other-modules: - build-depends: base >=2 && <=5, process, network >=2.4, bytestring, binary, containers, array, parallel + exposed-modules: Control.CUtils.Processes, Control.CUtils.NetChan, Control.CUtils.FChan, Control.CUtils.Deadlock, Control.CUtils.DataParallel, Control.CUtils.Conc, Control.CUtils.Channel, Control.CUtils.AList + other-modules: Control.CUtils.Split + build-depends: base >=4 && <=5, process, network >=2.4, bytestring, binary, containers, array, parallel
Control/CUtils/Channel.hs view
@@ -3,7 +3,7 @@ -- | A lock-free channel (queue) data structure. module Control.CUtils.Channel (Channel, newChannel, writeChannel, readChannel) where -import Control.Concurrent.SampleVar +import Control.Concurrent.MVar import Control.Monad import Data.IORef import Data.Bits @@ -22,8 +22,8 @@ (IORef Word32){-filled-} (IORef Word32){-maybe empty-} (IORef Word32){-empty-} - (SampleVar ()){-full lock-} - (SampleVar ()){-empty lock-} + (MVar ()){-full lock-} + (MVar ()){-empty lock-} -- | Create a channel with a buffer at least as big as 'buffer'. newChannel :: (MArray a t IO) => Word32 -> IO (Channel a t) @@ -41,8 +41,8 @@ e <- newIORef 0 -- Create locks - fl <- newSampleVar () - el <- newEmptySampleVar + fl <- newMVar () + el <- newEmptyMVar return (Channel buffer' a mf f me e fl el) @@ -54,12 +54,12 @@ yN <- readIORef y if yN + off <= mXN then do mYN <- readIORef my - when (yN == mYN) $ readSampleVar lx + when (yN == mYN) $ takeMVar lx spin else do val <- f a (mXN `mod` buffer) increment x - writeSampleVar ly () + tryPutMVar ly () return val spin