use a TMVar

SampleMVar won't work; between getting the current value and changing
it, another thread could made a change, which would get lost.

TMVar works well; this update situation is handled by atomic transactions.
This commit is contained in:
Joey Hess 2012-06-26 17:33:34 -04:00
parent e0a65247ae
commit 67c8ef7de2
4 changed files with 61 additions and 47 deletions

View file

@ -53,6 +53,9 @@
- CommitChan: (STM TChan)
- Commits are indicated by writing to this channel. The pusher reads
- from it.
- FailedPushMap (STM TMVar)
- Failed pushes are indicated by writing to this TMVar. The push
- retrier blocks until they're available.
-}
module Assistant where
@ -89,10 +92,10 @@ startDaemon assistant foreground
liftIO $ a $ do
changechan <- newChangeChan
commitchan <- newCommitChan
pushchan <- newFailedPushChan
pushmap <- newFailedPushMap
_ <- forkIO $ commitThread st changechan commitchan
_ <- forkIO $ pushThread st commitchan pushchan
_ <- forkIO $ pushRetryThread st pushchan
_ <- forkIO $ pushThread st commitchan pushmap
_ <- forkIO $ pushRetryThread st pushmap
_ <- forkIO $ mergeThread st
_ <- forkIO $ daemonStatusThread st dstatus
_ <- forkIO $ sanityCheckerThread st dstatus changechan