X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=System%2FEvent%2FManager.hs;h=9766774f550db0a49e50efe6fe004e57aa3ed0ad;hb=41e8fba828acbae1751628af50849f5352b27873;hp=1206d66db7acbf1e25a7e77880aa1df3480f325d;hpb=b35c301de87a9440b320994dcc788d44d80bcc45;p=ghc-base.git diff --git a/System/Event/Manager.hs b/System/Event/Manager.hs index 1206d66..9766774 100644 --- a/System/Event/Manager.hs +++ b/System/Event/Manager.hs @@ -1,5 +1,12 @@ -{-# LANGUAGE BangPatterns, CPP, ExistentialQuantification, NoImplicitPrelude, - RecordWildCards, TypeSynonymInstances #-} +{-# LANGUAGE BangPatterns + , CPP + , ExistentialQuantification + , NoImplicitPrelude + , RecordWildCards + , TypeSynonymInstances + , FlexibleInstances + #-} + module System.Event.Manager ( -- * Types EventManager @@ -14,6 +21,7 @@ module System.Event.Manager , loop , step , shutdown + , cleanup , wakeManager -- * Registering interest in I/O events @@ -96,6 +104,7 @@ type IOCallback = FdKey -> Event -> IO () instance Show IOCallback where show _ = "IOCallback" +-- | A timeout registration cookie. newtype TimeoutKey = TK Unique deriving (Eq) @@ -217,7 +226,8 @@ cleanup EventManager{..} = do ------------------------------------------------------------------------ -- Event loop --- | Start handling events. This function loops until told to stop. +-- | Start handling events. This function loops until told to stop, +-- using 'shutdown'. -- -- /Note/: This loop can only be run once per 'EventManager', as it -- closes all of its control resources when it finishes. @@ -346,7 +356,10 @@ closeFd mgr close fd = do ------------------------------------------------------------------------ -- Registering interest in timeout events --- | Register a timeout in the given number of microseconds. +-- | Register a timeout in the given number of microseconds. The +-- returned 'TimeoutKey' can be used to later unregister or update the +-- timeout. The timeout is automatically unregistered after the given +-- time has passed. registerTimeout :: EventManager -> Int -> TimeoutCallback -> IO TimeoutKey registerTimeout mgr us cb = do !key <- newUnique (emUniqueSource mgr) @@ -365,12 +378,15 @@ registerTimeout mgr us cb = do wakeManager mgr return $ TK key +-- | Unregister an active timeout. unregisterTimeout :: EventManager -> TimeoutKey -> IO () unregisterTimeout mgr (TK key) = do atomicModifyIORef (emTimeouts mgr) $ \f -> let f' = (Q.delete key) . f in (f', ()) wakeManager mgr +-- | Update an active timeout to fire in the given number of +-- microseconds. updateTimeout :: EventManager -> TimeoutKey -> Int -> IO () updateTimeout mgr (TK key) us = do now <- getCurrentTime