{-# LANGUAGE CPP #-}
module Control.Concurrent.Chan.Unagi.Bounded
#ifdef NOT_x86
{-# WARNING "This library is unlikely to perform well on architectures without a fetch-and-add instruction" #-}
#endif
#if __GLASGOW_HASKELL__ < 708
{-# WARNING "Waking up blocked writers may be slower than desired in GHC<7.8 which makes readMVar non-blocking on full MVars. Nextidering upgrading." #-}
#endif
(
newChan
, InChan(), OutChan()
, readChan
, readChanOnException
, tryReadChan
, Element(..)
, getChanContents
, estimatedLength
, writeChan
, tryWriteChan
, writeList2Chan
, dupChan
) where
import Control.Concurrent.Chan.Unagi.Bounded.Internal
import Control.Concurrent.Chan.Unagi.NoBlocking.Types
import System.IO.Unsafe ( unsafeInterleaveIO )
newChan :: Int -> IO (InChan a, OutChan a)
newChan size = newChanStarting (maxBound - 10) size
getChanContents :: OutChan a -> IO [a]
getChanContents ch = unsafeInterleaveIO (do
x <- unsafeInterleaveIO $ readChan ch
xs <- getChanContents ch
return (x:xs)
)
writeList2Chan :: InChan a -> [a] -> IO ()
{-# INLINABLE writeList2Chan #-}
writeList2Chan ch = sequence_ . map (writeChan ch)