on master help sign in
Revert "Use atomic-primops for Counter"
f65706cMichael Snoyman
warp/Network/Wai/Handler/Warp/Counter.hs+6−6
@@ -6,19 +6,19 @@ module Network.Wai.Handler.Warp.Counter (
6 , decrease
6 , decrease
7 ) where
7 ) where
8
8
9−import qualified Data.Atomics.Counter.Unboxed as C
9+import Network.Wai.Handler.Warp.IORef
10import Control.Applicative ((<$>))
10import Control.Applicative ((<$>))
11
11
12−newtype Counter = Counter C.AtomicCounter
12+newtype Counter = Counter (IORef Int)
13
13
14newCounter :: IO Counter
14newCounter :: IO Counter
15−newCounter = Counter <$> C.newCounter 0
15+newCounter = Counter <$> newIORef 0
16
16
17isZero :: Counter -> IO Bool
17isZero :: Counter -> IO Bool
18−isZero (Counter ref) = (== 0) <$> C.readCounter ref
18+isZero (Counter ref) = (== 0) <$> readIORef ref
19
19
20increase :: Counter -> IO ()
20increase :: Counter -> IO ()
21−increase (Counter ref) = C.incrCounter_ 1 ref
21+increase (Counter ref) = atomicModifyIORef' ref $ \x -> (x + 1, ())
22
22
23decrease :: Counter -> IO ()
23decrease :: Counter -> IO ()
24−decrease (Counter ref) = C.incrCounter_ (-1) ref
24+decrease (Counter ref) = atomicModifyIORef' ref $ \x -> (x - 1, ())
warp/warp.cabal−2
@@ -52,7 +52,6 @@ Library
52 , wai >= 3.0 && < 3.1
52 , wai >= 3.0 && < 3.1
53 , text
53 , text
54 , streaming-commons >= 0.1.2
54 , streaming-commons >= 0.1.2
55− , atomic-primops >= 0.6
56 if flag(network-bytestring)
55 if flag(network-bytestring)
57 Build-Depends: network >= 2.2.1.5 && < 2.2.3
56 Build-Depends: network >= 2.2.1.5 && < 2.2.3
58 , network-bytestring >= 0.1.3 && < 0.1.4
57 , network-bytestring >= 0.1.3 && < 0.1.4
@@ -144,7 +143,6 @@ Test-Suite spec
144 , text
143 , text
145 , streaming-commons >= 0.1.1
144 , streaming-commons >= 0.1.1
146 , async
145 , async
147− , atomic-primops
148
146
149 if (os(linux) || os(freebsd) || os(darwin)) && flag(allow-sendfilefd)
147 if (os(linux) || os(freebsd) || os(darwin)) && flag(allow-sendfilefd)
150 Cpp-Options: -DSENDFILEFD
148 Cpp-Options: -DSENDFILEFD