module Data.Atomics.Vector
( casVectorElem, unsafeCasVectorElem
, readVectorElem, unsafeReadVectorElem )
where
import Data.Atomics
import Data.Vector.Mutable
casVectorElem :: IOVector a -> Int -> Ticket a -> a -> IO (Bool, Ticket a)
casVectorElem (MVector st len array) i tick elm =
let idx = i + st
in if i >= len
then error $ "casVectorElem: out of bounds access to index "++show i++
" of IOVector of length "++show len
else casArrayElem array idx tick elm
unsafeCasVectorElem :: IOVector a -> Int -> Ticket a -> a -> IO (Bool, Ticket a)
unsafeCasVectorElem (MVector st _ array) i tick elm =
let idx = i + st
in casArrayElem array idx tick elm
readVectorElem :: IOVector a -> Int -> IO (Ticket a)
readVectorElem (MVector st len arr) ix =
if ix >= len
then error $ "readVectorElem: out of bounds access to index "++show ix++
" of IOVector of length "++show len
else readArrayElem arr (st + ix)
unsafeReadVectorElem :: IOVector a -> Int -> IO (Ticket a)
unsafeReadVectorElem (MVector st _ arr) ix = readArrayElem arr (st + ix)