on master help sign in
Revert "Only use atomic-primops on GHC 7.8"

This reverts commit a7a78e64096359520d84e5ce7583810339fac0a9.

commitbc7f421e7af34f07da557939f663065a4c42ec80 authorMichael Snoyman <michael@snoyman.com> dateFri 3 Oct 2014, 08:27 (12 years ago) parenta7a78e6
3 files changed+8−65
warp/Network/Wai/Handler/Warp/Counter.hs−21 warp/Network/Wai/Handler/Warp/Timeout.hs+5−35 warp/warp.cabal+3−9
warp/Network/Wai/Handler/Warp/Counter.hs−21
@@ -1,4 +1,3 @@
1−{-# LANGUAGE CPP #-}
21module Network.Wai.Handler.Warp.Counter (
32 Counter
43 , newCounter
@@ -7,7 +6,6 @@ module Network.Wai.Handler.Warp.Counter (
76 , decrease
87 ) where
98
10−#if USE_ATOMIC_PRIMOPS
119import qualified Data.Atomics.Counter.Unboxed as C
1210import Control.Applicative ((<$>))
1311
@@ -24,22 +22,3 @@ increase (Counter ref) = C.incrCounter_ 1 ref
2422
2523decrease :: Counter -> IO ()
2624decrease (Counter ref) = C.incrCounter_ (-1) ref
27−#else
28−
29−import Network.Wai.Handler.Warp.IORef
30−import Control.Applicative ((<$>))
31−
32−newtype Counter = Counter (IORef Int)
33−
34−newCounter :: IO Counter
35−newCounter = Counter <$> newIORef 0
36−
37−isZero :: Counter -> IO Bool
38−isZero (Counter ref) = (== 0) <$> readIORef ref
39−
40−increase :: Counter -> IO ()
41−increase (Counter ref) = atomicModifyIORef' ref (\x -> (x + 1, ()))
42−
43−decrease :: Counter -> IO ()
44−decrease (Counter ref) = atomicModifyIORef' ref (\x -> (x - 1, ()))
45−#endif
warp/Network/Wai/Handler/Warp/Timeout.hs+5−35
@@ -59,12 +59,7 @@ import GHC.Weak (Weak (..))
5959import System.Mem.Weak (deRefWeak)
6060import Data.Typeable (Typeable)
6161import Control.Reaper
62−#if USE_ATOMIC_PRIMOPS
6362import qualified Data.Atomics.Counter.Unboxed as C
64−import Data.Atomics.Counter.Unboxed (casCounter)
65−#else
66−import Network.Wai.Handler.Warp.IORef
67−#endif
6863
6964----------------------------------------------------------------
7065
@@ -75,12 +70,7 @@ type Manager = Reaper [Handle] Handle
7570type TimeoutAction = IO ()
7671
7772-- | A handle used by 'Manager'
78−data Handle = Handle TimeoutAction
79−#if USE_ATOMIC_PRIMOPS
80− {-# UNPACK #-} !C.AtomicCounter
81−#else
82− {-# UNPACK #-} !(IORef Int)
83−#endif
73+data Handle = Handle TimeoutAction {-# UNPACK #-} !C.AtomicCounter
8474
8575-- Four states for the AtomicCounter:
8676--
@@ -101,7 +91,7 @@ initialize timeout = mkReaper defaultReaperSettings
10191 where
10292 prune m@(Handle onTimeout iactive) = do
10393 -- Try to change from active to inactive
104− (wasActive, newState) <- casCounter iactive 1 2
94+ (wasActive, newState) <- C.casCounter iactive 1 2
10595 case newState of
10696 2 | not wasActive -> do -- inactive
10797 onTimeout `E.catch` ignoreAll
@@ -109,14 +99,6 @@ initialize timeout = mkReaper defaultReaperSettings
10999 4 -> return Nothing -- canceled
110100 _ -> return $ Just m
111101
112−#if !USE_ATOMIC_PRIMOPS
113−casCounter :: IORef Int -> Int -> Int -> IO (Bool, Int)
114−casCounter ref old new = atomicModifyIORef' ref $ \curr ->
115− if old == curr
116− then (new, (True, new))
117− else (old, (False, old))
118−#endif
119−
120102----------------------------------------------------------------
121103
122104-- | Stopping timeout manager.
@@ -133,11 +115,7 @@ ignoreAll _ = return ()
133115-- | Registering a timeout action.
134116register :: Manager -> TimeoutAction -> IO Handle
135117register mgr onTimeout = do
136−#if USE_ATOMIC_PRIMOPS
137118 iactive <- C.newCounter 1
138−#else
139− iactive <- newIORef 1
140−#endif
141119 let h = Handle onTimeout iactive
142120 reaperAdd mgr h
143121 return h
@@ -171,28 +149,20 @@ mkWeakThreadId t@(ThreadId t#) = IO $ \s ->
171149
172150----------------------------------------------------------------
173151
174−writeCounter :: Int -> Handle -> IO ()
175−#if USE_ATOMIC_PRIMOPS
176−writeCounter i (Handle _ iactive) = C.writeCounter iactive i
177−#else
178−writeCounter i (Handle _ iactive) = writeIORef iactive i
179−#endif
180−{-# INLINE writeCounter #-}
181−
182152-- | Setting the state to active.
183153-- 'Manager' turns active to inactive repeatedly.
184154tickle :: Handle -> IO ()
185−tickle = writeCounter 1
155+tickle (Handle _ iactive) = C.writeCounter iactive 1
186156
187157-- | Setting the state to canceled.
188158-- 'Manager' eventually removes this without timeout action.
189159cancel :: Handle -> IO ()
190−cancel = writeCounter 4
160+cancel (Handle _ iactive) = C.writeCounter iactive 4
191161
192162-- | Setting the state to paused.
193163-- 'Manager' does not change the value.
194164pause :: Handle -> IO ()
195−pause = writeCounter 3
165+pause (Handle _ iactive) = C.writeCounter iactive 3
196166
197167-- | Setting the paused state to active.
198168-- This is an alias to 'tickle'.
warp/warp.cabal+3−9
@@ -1,5 +1,5 @@
11Name: warp
2−Version: 3.0.2.2
2+Version: 3.0.2.1
33Synopsis: A fast, light-weight web server for WAI applications.
44License: MIT
55License-file: LICENSE
@@ -52,10 +52,7 @@ Library
5252 , wai >= 3.0 && < 3.1
5353 , text
5454 , streaming-commons >= 0.1.2
55−
56− if impl(ghc >= 7.8)
57− Build-Depends: atomic-primops >= 0.6
58− cpp-options: -DUSE_ATOMIC_PRIMOPS
55+ , atomic-primops >= 0.6
5956 if flag(network-bytestring)
6057 Build-Depends: network >= 2.2.1.5 && < 2.2.3
6158 , network-bytestring >= 0.1.3 && < 0.1.4
@@ -147,10 +144,7 @@ Test-Suite spec
147144 , text
148145 , streaming-commons >= 0.1.1
149146 , async
150−
151− if impl(ghc >= 7.8)
152− Build-Depends: atomic-primops >= 0.6
153− cpp-options: -DUSE_ATOMIC_PRIMOPS
147+ , atomic-primops
154148
155149 if (os(linux) || os(freebsd) || os(darwin)) && flag(allow-sendfilefd)
156150 Cpp-Options: -DSENDFILEFD