module System.Metrics.Gauge
(
Gauge
, new
, read
, inc
, dec
, add
, subtract
, set
) where
import qualified Data.Atomic as Atomic
import Data.Int (Int64)
import Prelude hiding (subtract, read)
newtype Gauge = C { unC :: Atomic.Atomic }
new :: IO Gauge
new = C `fmap` Atomic.new 0
read :: Gauge -> IO Int64
read = Atomic.read . unC
inc :: Gauge -> IO ()
inc gauge = add gauge 1
dec :: Gauge -> IO ()
dec gauge = subtract gauge 1
add :: Gauge -> Int64 -> IO ()
add gauge = Atomic.add (unC gauge)
subtract :: Gauge -> Int64 -> IO ()
subtract gauge = Atomic.subtract (unC gauge)
set :: Gauge -> Int64 -> IO ()
set gauge = Atomic.write (unC gauge)