Copyright | (c) Sergey Vinokurov 2022 |
---|---|
License | Apache-2.0 (see LICENSE) |
Maintainer | serg.foo@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Counters that support some atomic operations. Safe to use from multiple threads and likely faster than using IORef or TVar for the same operation (terms and conditions apply).
Synopsis
- data Counter s
- new :: Int -> ST s (Counter s)
- get :: Counter s -> ST s Int
- set :: Counter s -> Int -> ST s ()
- add :: Counter s -> Int -> ST s Int
- sub :: Counter s -> Int -> ST s Int
- and :: Counter s -> Int -> ST s Int
- or :: Counter s -> Int -> ST s Int
- xor :: Counter s -> Int -> ST s Int
- nand :: Counter s -> Int -> ST s Int
Documentation
Memory location that supports select few atomic operations.
Isomorphic to STRef s Int
.
Create
Read/write
Arithmetic operations
add :: Counter s -> Int -> ST s Int Source #
Atomically add an amount to the counter and return its old value.
sub :: Counter s -> Int -> ST s Int Source #
Atomically subtract an amount from the counter and return its old value.
Bitwise operations
and :: Counter s -> Int -> ST s Int Source #
Atomically combine old value with a new one via bitwise and. Returns old counter value.
or :: Counter s -> Int -> ST s Int Source #
Atomically combine old value with a new one via bitwise or. Returns old counter value.