diff options
Diffstat (limited to 'Assistant/Pushes.hs')
-rw-r--r-- | Assistant/Pushes.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Assistant/Pushes.hs b/Assistant/Pushes.hs index f411dda07..49772d56a 100644 --- a/Assistant/Pushes.hs +++ b/Assistant/Pushes.hs @@ -8,8 +8,10 @@ module Assistant.Pushes where import Common.Annex +import Utility.TSet import Control.Concurrent.STM +import Control.Concurrent.MSampleVar import Data.Time.Clock import qualified Data.Map as M @@ -17,6 +19,14 @@ import qualified Data.Map as M type PushMap = M.Map Remote UTCTime type FailedPushMap = TMVar PushMap +{- The TSet is recent, successful pushes that other remotes should be + - notified about. + - + - The MSampleVar is written to when the PushNotifier thread should be + - restarted for some reason. + -} +data PushNotifier = PushNotifier (TSet UUID) (MSampleVar ()) + {- The TMVar starts empty, and is left empty when there are no - failed pushes. This way we can block until there are some failed pushes. -} @@ -44,3 +54,20 @@ changeFailedPushMap v a = atomically $ store m | m == M.empty = noop | otherwise = putTMVar v $! m + +newPushNotifier :: IO PushNotifier +newPushNotifier = PushNotifier + <$> newTSet + <*> newEmptySV + +notifyPush :: [UUID] -> PushNotifier -> IO () +notifyPush us (PushNotifier s _) = putTSet s us + +waitPush :: PushNotifier -> IO [UUID] +waitPush (PushNotifier s _) = getTSet s + +notifyRestart :: PushNotifier -> IO () +notifyRestart (PushNotifier _ sv) = writeSV sv () + +waitRestart :: PushNotifier -> IO () +waitRestart (PushNotifier _ sv) = readSV sv |