----------------------------------------------------------------------------- -- | -- Module : Data.Counters -- Copyright : (c) 2020-2021 EMQ Technologies Co., Ltd. -- License : BSD-style (see the LICENSE file) -- -- Maintainer : Feng Lee, feng@emqx.io -- Yang M, yangm@emqx.io -- Stability : experimental -- Portability : portable -- -- The Counters module. -- ----------------------------------------------------------------------------- module Data.Counters where import Control.Monad (IO) import Data.Unit (Unit) import Foreign (ffiIO1, ffiIO2, ffiIO3) foreign import data CountersRef :: Type data CountersOpt = Atomics | WriteConcurrency type CountersInfo = { size :: Integer -- ^ The number of counters in the array. , memory :: Integer -- ^ Approximate memory consumption for the array in bytes. } foreign import new :: Integer -> CountersOpt -> IO CountersRef get :: CountersRef -> Integer -> IO Integer get = ffiIO2 :counters :get add :: CountersRef -> Integer -> Integer -> IO () add = ffiIO3 :counters :add sub :: CountersRef -> Integer -> Integer -> IO () sub = ffiIO3 :counters :sub put :: CountersRef -> Integer -> Integer -> IO () put = ffiIO3 :counters :put info :: CountersRef -> IO CountersInfo info = ffiIO1 :counters :info