summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2015-12-17 15:31:50 -0500
committerAndrew Cady <d@jerkface.net>2015-12-17 15:31:50 -0500
commit4ffd34ff263145b65b280118214d0c2721832427 (patch)
treef4a98e312a82f6a0761e75197af5d08ab5ae4a39
parentc60236caa5ad92d1eb20959023e2f4a548c8d1a4 (diff)
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.
-rw-r--r--axis-of-eval.cabal2
-rw-r--r--midi-dump.hs10
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
40 transformers, semigroups, HCodecs, threads 40 transformers, semigroups, HCodecs, threads
41 main-is: midi-dump.hs 41 main-is: midi-dump.hs
42 other-modules: AlsaSeq, Midi, RealTimeQueue 42 other-modules: AlsaSeq, Midi, RealTimeQueue
43 ghc-options: -threaded -W -Wall -O2 43 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
221 else delay >> mainLoop 221 else delay >> mainLoop
222 222
223 where 223 where
224 tickDuration = 5000 -- 5ms 224 tickDurationMilliseconds = 4
225
226 tickDuration = TimeSpec 0 (tickDurationMilliseconds * 10^(6::Int64))
225 delay = do 227 delay = do
226 before <- gets _lastTick 228 before <- gets _lastTick
229 liftIO performMinorGC
227 after <- getAbsTime 230 after <- getAbsTime
228 if after - before < fromIntegral (10^(6::Int) * tickDuration) then 231 let duration = tickDuration - (after - before)
229 liftIO $ threadDelay $ tickDuration - fromIntegral (nsec after - nsec before) `div` 1000 232 if duration > 0 then
233 liftIO $ threadDelay $ fromIntegral (nsec duration) `div` 1000
230 else 234 else
231 liftIO $ putStrLn "Uh oh! Dropped frame!" 235 liftIO $ putStrLn "Uh oh! Dropped frame!"
232 mainLoop 236 mainLoop