diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-10-28 19:43:34 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-10-28 19:44:31 -0400 |
| commit | d44f0b46d78060d36e8171b7278b63b6821a9889 (patch) | |
| tree | 087d06c3b20db2dbf271c287b322f6c0912d1a1a /src/Utility/ConcurrentOutput.hs | |
| parent | c85ca96d70f328fb799019a604b7ba82daa0aa33 (diff) | |
export lockOutput
Diffstat (limited to 'src/Utility/ConcurrentOutput.hs')
| -rw-r--r-- | src/Utility/ConcurrentOutput.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Utility/ConcurrentOutput.hs b/src/Utility/ConcurrentOutput.hs index 31871977..db0bae0a 100644 --- a/src/Utility/ConcurrentOutput.hs +++ b/src/Utility/ConcurrentOutput.hs @@ -8,6 +8,7 @@ module Utility.ConcurrentOutput ( outputConcurrent, createProcessConcurrent, waitForProcessConcurrent, + lockOutput, ) where import System.IO @@ -53,8 +54,11 @@ globalOutputHandle = unsafePerformIO $ getOutputHandle :: IO OutputHandle getOutputHandle = readMVar globalOutputHandle --- | Holds a lock while performing an action. Any other threads --- that try to lockOutput at the same time will block. +-- | Holds a lock while performing an action that will display output. +-- While this is running, other threads that try to lockOutput will block, +-- and calls to `outputConcurrent` and `createProcessConcurrent` +-- will result in that concurrent output being buffered and not +-- displayed until the action is done. lockOutput :: (MonadIO m, MonadMask m) => m a -> m a lockOutput = bracket_ (liftIO takeOutputLock) (liftIO dropOutputLock) @@ -253,8 +257,8 @@ outputDrainer ss fromh buf bufsig -- Wait to lock output, and once we can, display everything -- that's put into the buffers, until the end. bufferWriter :: [(Handle, MVar Buffer, TMVar ())] -> IO () -bufferWriter l = do - worker <- async $ void $ lockOutput $ mapConcurrently go l +bufferWriter ts = do + worker <- async $ void $ lockOutput $ mapConcurrently go ts v <- outputThreads <$> getOutputHandle atomically $ do s <- takeTMVar v |
