From 4ffd34ff263145b65b280118214d0c2721832427 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 17 Dec 2015 15:31:50 -0500 Subject: Perform GC for each tick. The per-tick delay takes account of the time spent in GC. Also, changed tick time to 4ms and fixed TimeSpec arithmetic/logic. --- axis-of-eval.cabal | 2 +- midi-dump.hs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/axis-of-eval.cabal b/axis-of-eval.cabal index d1aee15..f09386a 100644 --- a/axis-of-eval.cabal +++ b/axis-of-eval.cabal @@ -40,4 +40,4 @@ executable midi-dump transformers, semigroups, HCodecs, threads main-is: midi-dump.hs other-modules: AlsaSeq, Midi, RealTimeQueue - ghc-options: -threaded -W -Wall -O2 + ghc-options: -threaded -W -Wall -O2 -rtsopts diff --git a/midi-dump.hs b/midi-dump.hs index 59a9df5..275593d 100644 --- a/midi-dump.hs +++ b/midi-dump.hs @@ -221,12 +221,16 @@ mainLoop = do else delay >> mainLoop where - tickDuration = 5000 -- 5ms + tickDurationMilliseconds = 4 + + tickDuration = TimeSpec 0 (tickDurationMilliseconds * 10^(6::Int64)) delay = do before <- gets _lastTick + liftIO performMinorGC after <- getAbsTime - if after - before < fromIntegral (10^(6::Int) * tickDuration) then - liftIO $ threadDelay $ tickDuration - fromIntegral (nsec after - nsec before) `div` 1000 + let duration = tickDuration - (after - before) + if duration > 0 then + liftIO $ threadDelay $ fromIntegral (nsec duration) `div` 1000 else liftIO $ putStrLn "Uh oh! Dropped frame!" mainLoop -- cgit v1.2.3