summaryrefslogtreecommitdiff
path: root/Utility/ThreadScheduler.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-17 14:02:40 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-17 14:02:40 -0400
commite84b78f40c5ae20031c1d5cdde524081774de656 (patch)
tree909198899fa9682d9cca0a0cae52a8ff806d6ed5 /Utility/ThreadScheduler.hs
parent9356f11c6077f61e6bda9758f12b3f76b68991e3 (diff)
reorg
Diffstat (limited to 'Utility/ThreadScheduler.hs')
-rw-r--r--Utility/ThreadScheduler.hs15
1 files changed, 15 insertions, 0 deletions
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