on master help sign in
Use atomic-primops for Counter
commit0247207811dcc66374199efe5da7ca04a2c34d50 authorMichael Snoyman <michael@snoyman.com> dateWed 1 Oct 2014, 11:50 (12 years ago) parent2b1cc88
2 files changed+8−6
warp/Network/Wai/Handler/Warp/Counter.hs+6−6 warp/warp.cabal+2
warp/Network/Wai/Handler/Warp/Counter.hs+6−6
@@ -6,19 +6,19 @@ module Network.Wai.Handler.Warp.Counter (
66 , decrease
77 ) where
88
9−import Network.Wai.Handler.Warp.IORef
9+import qualified Data.Atomics.Counter.Unboxed as C
1010import Control.Applicative ((<$>))
1111
12−newtype Counter = Counter (IORef Int)
12+newtype Counter = Counter C.AtomicCounter
1313
1414newCounter :: IO Counter
15−newCounter = Counter <$> newIORef 0
15+newCounter = Counter <$> C.newCounter 0
1616
1717isZero :: Counter -> IO Bool
18−isZero (Counter ref) = (== 0) <$> readIORef ref
18+isZero (Counter ref) = (== 0) <$> C.readCounter ref
1919
2020increase :: Counter -> IO ()
21−increase (Counter ref) = atomicModifyIORef' ref $ \x -> (x + 1, ())
21+increase (Counter ref) = C.incrCounter_ 1 ref
2222
2323decrease :: Counter -> IO ()
24−decrease (Counter ref) = atomicModifyIORef' ref $ \x -> (x - 1, ())
24+decrease (Counter ref) = C.incrCounter_ (-1) ref
warp/warp.cabal+2
@@ -52,6 +52,7 @@ Library
5252 , wai >= 3.0 && < 3.1
5353 , text
5454 , streaming-commons >= 0.1.2
55+ , atomic-primops >= 0.6
5556 if flag(network-bytestring)
5657 Build-Depends: network >= 2.2.1.5 && < 2.2.3
5758 , network-bytestring >= 0.1.3 && < 0.1.4
@@ -143,6 +144,7 @@ Test-Suite spec
143144 , text
144145 , streaming-commons >= 0.1.1
145146 , async
147+ , atomic-primops
146148
147149 if (os(linux) || os(freebsd) || os(darwin)) && flag(allow-sendfilefd)
148150 Cpp-Options: -DSENDFILEFD