Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doTick: use exception-safe modifyMVar_ instead of takeMVar/putMVar #1100

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Sound/Tidal/Stream/Process.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ doTick :: MVar ValueMap -- pattern state
-> (Link.SessionState, Link.SessionState) -- second session state is for keeping track of tempo changes
-> IO ()
doTick stateMV busMV playMV globalFMV cxs listen (st,end) nudge cconf cref (ss, temposs) =
E.handle (\ (e :: E.SomeException) -> do
hPutStrLn stderr $ "Failed to Stream.doTick: " ++ show e
hPutStrLn stderr $ "Return to previous pattern."
setPreviousPatternOrSilence playMV) (do
sMap <- takeMVar stateMV
E.handle handleException $ do
modifyMVar_ stateMV $ \sMap -> do
pMap <- readMVar playMV
busses <- readMVar busMV
sGlobalF <- readMVar globalFMV
Expand All @@ -122,7 +119,13 @@ doTick stateMV busMV playMV globalFMV cxs listen (st,end) nudge cconf cref (ss,
-- send the events to the OSC target
forM_ ms $ \m -> (send listen cx latency extraLatency m) `E.catch` \(e :: E.SomeException) ->
hPutStrLn stderr $ "Failed to send. Is the '" ++ oName target ++ "' target running? " ++ show e
putMVar stateMV sMap'')
return sMap''
where
handleException :: E.SomeException -> IO ()
handleException e = do
hPutStrLn stderr $ "Failed to Stream.doTick: " ++ show e
hPutStrLn stderr $ "Return to previous pattern."
setPreviousPatternOrSilence playMV

processCps :: Clock.ClockConfig -> Clock.ClockRef -> (Link.SessionState, Link.SessionState) -> [Event ValueMap] -> IO [ProcessedEvent]
processCps cconf cref (ss, temposs) = mapM processEvent
Expand Down
Loading