@@ -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