From e84b78f40c5ae20031c1d5cdde524081774de656 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 17 Jun 2012 14:02:40 -0400 Subject: reorg --- Utility/ThreadScheduler.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Utility/ThreadScheduler.hs') diff --git a/Utility/ThreadScheduler.hs b/Utility/ThreadScheduler.hs index 9204cd9b9..6557398fd 100644 --- a/Utility/ThreadScheduler.hs +++ b/Utility/ThreadScheduler.hs @@ -9,7 +9,10 @@ module Utility.ThreadScheduler where import Common + import Control.Concurrent +import System.Posix.Terminal +import System.Posix.Signals newtype Seconds = Seconds { fromSeconds :: Int } deriving (Eq, Ord, Show) @@ -40,3 +43,15 @@ unboundDelay time = do let maxWait = min time $ toInteger (maxBound :: Int) threadDelay $ fromInteger maxWait when (maxWait /= time) $ unboundDelay (time - maxWait) + +{- Pauses the main thread, letting children run until program termination. -} +waitForTermination :: IO () +waitForTermination = do + lock <- newEmptyMVar + check softwareTermination lock + whenM (queryTerminal stdInput) $ + check keyboardSignal lock + takeMVar lock + where + check sig lock = void $ + installHandler sig (CatchOnce $ putMVar lock ()) Nothing -- cgit v1.2.3