summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-10 13:56:43 -0400
committerjoe <joe@jerkface.net>2018-06-10 13:56:43 -0400
commit4cb899c4af5e2933c39e295633164321b3420795 (patch)
tree43a5be5002b3efc9ddc9be109c4033aea507d5d5
parentefabb55dfeb6a809f5193b241e490024fbee6f7c (diff)
Tweaks to announce scheduler.
-rw-r--r--Announcer.hs10
-rw-r--r--examples/dhtd.hs3
2 files changed, 10 insertions, 3 deletions
diff --git a/Announcer.hs b/Announcer.hs
index c66d26b4..140ee993 100644
--- a/Announcer.hs
+++ b/Announcer.hs
@@ -36,6 +36,7 @@ import Data.Ord
36import Data.Time.Clock.POSIX 36import Data.Time.Clock.POSIX
37import qualified GHC.Generics as Generics 37import qualified GHC.Generics as Generics
38-- import Generic.Data.Internal.Meta as Lyxia 38-- import Generic.Data.Internal.Meta as Lyxia
39import System.IO
39 40
40newtype AnnounceKey = AnnounceKey ByteString 41newtype AnnounceKey = AnnounceKey ByteString
41 deriving (Hashable,Ord,Eq) 42 deriving (Hashable,Ord,Eq)
@@ -179,7 +180,11 @@ schedule announcer k AnnounceMethod{aSearch,aPublish,aBuckets,aTarget,aInterval}
179 -- atomically $ modifyTVar ns $ MM.insertTake announceK ni (Down now) 180 -- atomically $ modifyTVar ns $ MM.insertTake announceK ni (Down now)
180 return () 181 return ()
181 return True -- True to keep searching. 182 return True -- True to keep searching.
182 searchAgain = searchIsFinished st >>= \isfin -> return $ when isfin $ void $ fork search 183 searchAgain = do
184 -- Canceling a pending search here seems to make announcements more reliable.
185 searchCancel st
186 isfin <- searchIsFinished st -- Always True, since we canceled.
187 return $ when isfin $ void $ fork search
183 search = do -- thread to fork 188 search = do -- thread to fork
184 atomically $ reset aBuckets aSearch aTarget st 189 atomically $ reset aBuckets aSearch aTarget st
185 searchLoop aSearch aTarget onResult st 190 searchLoop aSearch aTarget onResult st
@@ -225,7 +230,7 @@ announceThread announcer = do
225 return $ do 230 return $ do
226 now <- getPOSIXTime 231 now <- getPOSIXTime
227 -- Is it time to do something? 232 -- Is it time to do something?
228 if (prio item < now) 233 if (prio item <= now)
229 then do -- Yes. Dequeue and handle this event. 234 then do -- Yes. Dequeue and handle this event.
230 action <- atomically $ do 235 action <- atomically $ do
231 modifyTVar' (scheduled announcer) 236 modifyTVar' (scheduled announcer)
@@ -263,6 +268,7 @@ performScheduledItem announcer now = \case
263 (PSQ.insert' k (Announce checkFin announce interval) (now + interval)) 268 (PSQ.insert' k (Announce checkFin announce interval) (now + interval))
264 return $ Just $ do 269 return $ Just $ do
265 isfin 270 isfin
271 hPutStrLn stderr $ "This print avoids negative-time future scheduling. Weird bug. TODO: fix it. "++show now
266 announce 272 announce
267 273
268 -- search finished: 274 -- search finished:
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 58a69c6a..d6da567a 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -988,7 +988,8 @@ clientSession s@Session{..} sock cnum h = do
988 as <- readTVar (scheduled $ announcer) 988 as <- readTVar (scheduled $ announcer)
989 forM (PSQ.toList as) $ \(k,ptm,item) -> do 989 forM (PSQ.toList as) $ \(k,ptm,item) -> do
990 kstr <- unpackAnnounceKey announcer k 990 kstr <- unpackAnnounceKey announcer k
991 return [ show (ptm - now) 991 return [ if ptm==0 then "now"
992 else show (ptm - now)
992 , show (itemStatusNum item) 993 , show (itemStatusNum item)
993 , kstr 994 , kstr
994 ] 995 ]