module System.Metrics.Counter
(
Counter
, new
, read
, inc
, add
) where
import qualified Data.Atomic as Atomic
import Data.Int (Int64)
import Prelude hiding (read)
newtype Counter = C { Counter -> Atomic
unC :: Atomic.Atomic }
new :: IO Counter
new :: IO Counter
new = Atomic -> Counter
C (Atomic -> Counter) -> IO Atomic -> IO Counter
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Int64 -> IO Atomic
Atomic.new Int64
0
read :: Counter -> IO Int64
read :: Counter -> IO Int64
read = Atomic -> IO Int64
Atomic.read (Atomic -> IO Int64) -> (Counter -> Atomic) -> Counter -> IO Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Counter -> Atomic
unC
inc :: Counter -> IO ()
inc :: Counter -> IO ()
inc Counter
counter = Counter -> Int64 -> IO ()
add Counter
counter Int64
1
add :: Counter -> Int64 -> IO ()
add :: Counter -> Int64 -> IO ()
add Counter
counter = Atomic -> Int64 -> IO ()
Atomic.add (Counter -> Atomic
unC Counter
counter)