warp 3.0.2.2 → 3.0.2.3
raw patch · 3 files changed
+20/−78 lines, 3 filesdep −atomic-primopsdep ~base
Dependencies removed: atomic-primops
Dependency ranges changed: base
Files
- Network/Wai/Handler/Warp/Counter.hs +2/−23
- Network/Wai/Handler/Warp/Timeout.hs +17/−46
- warp.cabal +1/−9
Network/Wai/Handler/Warp/Counter.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} module Network.Wai.Handler.Warp.Counter ( Counter , newCounter@@ -7,25 +6,6 @@ , decrease ) where -#if USE_ATOMIC_PRIMOPS-import qualified Data.Atomics.Counter.Unboxed as C-import Control.Applicative ((<$>))--newtype Counter = Counter C.AtomicCounter--newCounter :: IO Counter-newCounter = Counter <$> C.newCounter 0--isZero :: Counter -> IO Bool-isZero (Counter ref) = (== 0) <$> C.readCounter ref--increase :: Counter -> IO ()-increase (Counter ref) = C.incrCounter_ 1 ref--decrease :: Counter -> IO ()-decrease (Counter ref) = C.incrCounter_ (-1) ref-#else- import Network.Wai.Handler.Warp.IORef import Control.Applicative ((<$>)) @@ -38,8 +18,7 @@ isZero (Counter ref) = (== 0) <$> readIORef ref increase :: Counter -> IO ()-increase (Counter ref) = atomicModifyIORef' ref (\x -> (x + 1, ()))+increase (Counter ref) = atomicModifyIORef' ref $ \x -> (x + 1, ()) decrease :: Counter -> IO ()-decrease (Counter ref) = atomicModifyIORef' ref (\x -> (x - 1, ()))-#endif+decrease (Counter ref) = atomicModifyIORef' ref $ \x -> (x - 1, ())
Network/Wai/Handler/Warp/Timeout.hs view
@@ -56,15 +56,11 @@ import Control.Concurrent (myThreadId) import qualified Control.Exception as E import GHC.Weak (Weak (..))+import Network.Wai.Handler.Warp.IORef (IORef)+import qualified Network.Wai.Handler.Warp.IORef as I import System.Mem.Weak (deRefWeak) import Data.Typeable (Typeable) import Control.Reaper-#if USE_ATOMIC_PRIMOPS-import qualified Data.Atomics.Counter.Unboxed as C-import Data.Atomics.Counter.Unboxed (casCounter)-#else-import Network.Wai.Handler.Warp.IORef-#endif ---------------------------------------------------------------- @@ -75,19 +71,12 @@ type TimeoutAction = IO () -- | A handle used by 'Manager'-data Handle = Handle TimeoutAction-#if USE_ATOMIC_PRIMOPS- {-# UNPACK #-} !C.AtomicCounter-#else- {-# UNPACK #-} !(IORef Int)-#endif+data Handle = Handle TimeoutAction (IORef State) --- Four states for the AtomicCounter:------ 1: Active -- Manager turns it to Inactive.--- 2: Inactive -- Manager removes it with timeout action.--- 3: Paused -- Manager does not change it.--- 4: Canceled -- Manager removes it without timeout action.+data State = Active -- Manager turns it to Inactive.+ | Inactive -- Manager removes it with timeout action.+ | Paused -- Manager does not change it.+ | Canceled -- Manager removes it without timeout action. ---------------------------------------------------------------- @@ -100,22 +89,16 @@ } where prune m@(Handle onTimeout iactive) = do- -- Try to change from active to inactive- (wasActive, newState) <- casCounter iactive 1 2- case newState of- 2 | not wasActive -> do -- inactive+ state <- I.atomicModifyIORef' iactive (\x -> (inactivate x, x))+ case state of+ Inactive -> do onTimeout `E.catch` ignoreAll return Nothing- 4 -> return Nothing -- canceled+ Canceled -> return Nothing _ -> return $ Just m -#if !USE_ATOMIC_PRIMOPS-casCounter :: IORef Int -> Int -> Int -> IO (Bool, Int)-casCounter ref old new = atomicModifyIORef' ref $ \curr ->- if old == curr- then (new, (True, new))- else (old, (False, old))-#endif+ inactivate Active = Inactive+ inactivate x = x ---------------------------------------------------------------- @@ -133,11 +116,7 @@ -- | Registering a timeout action. register :: Manager -> TimeoutAction -> IO Handle register mgr onTimeout = do-#if USE_ATOMIC_PRIMOPS- iactive <- C.newCounter 1-#else- iactive <- newIORef 1-#endif+ iactive <- I.newIORef Active let h = Handle onTimeout iactive reaperAdd mgr h return h@@ -171,28 +150,20 @@ ---------------------------------------------------------------- -writeCounter :: Int -> Handle -> IO ()-#if USE_ATOMIC_PRIMOPS-writeCounter i (Handle _ iactive) = C.writeCounter iactive i-#else-writeCounter i (Handle _ iactive) = writeIORef iactive i-#endif-{-# INLINE writeCounter #-}- -- | Setting the state to active. -- 'Manager' turns active to inactive repeatedly. tickle :: Handle -> IO ()-tickle = writeCounter 1+tickle (Handle _ iactive) = I.writeIORef iactive Active -- | Setting the state to canceled. -- 'Manager' eventually removes this without timeout action. cancel :: Handle -> IO ()-cancel = writeCounter 4+cancel (Handle _ iactive) = I.writeIORef iactive Canceled -- | Setting the state to paused. -- 'Manager' does not change the value. pause :: Handle -> IO ()-pause = writeCounter 3+pause (Handle _ iactive) = I.writeIORef iactive Paused -- | Setting the paused state to active. -- This is an alias to 'tickle'.
warp.cabal view
@@ -1,5 +1,5 @@ Name: warp-Version: 3.0.2.2+Version: 3.0.2.3 Synopsis: A fast, light-weight web server for WAI applications. License: MIT License-file: LICENSE@@ -52,10 +52,6 @@ , wai >= 3.0 && < 3.1 , text , streaming-commons >= 0.1.2-- if impl(ghc >= 7.8)- Build-Depends: atomic-primops >= 0.6- cpp-options: -DUSE_ATOMIC_PRIMOPS if flag(network-bytestring) Build-Depends: network >= 2.2.1.5 && < 2.2.3 , network-bytestring >= 0.1.3 && < 0.1.4@@ -147,10 +143,6 @@ , text , streaming-commons >= 0.1.1 , async-- if impl(ghc >= 7.8)- Build-Depends: atomic-primops >= 0.6- cpp-options: -DUSE_ATOMIC_PRIMOPS if (os(linux) || os(freebsd) || os(darwin)) && flag(allow-sendfilefd) Cpp-Options: -DSENDFILEFD