packages feed

atomic-primops-vector (empty) → 0.1.0.0

raw patch · 5 files changed

+127/−0 lines, 5 filesdep +atomic-primopsdep +atomic-primops-vectordep +basesetup-changed

Dependencies added: atomic-primops, atomic-primops-vector, base, primitive, vector

Files

+ Data/Atomics/Vector.hs view
@@ -0,0 +1,37 @@++module Data.Atomics.Vector+       ( casVectorElem, unsafeCasVectorElem+       , readVectorElem, unsafeReadVectorElem )+       where++import Data.Atomics+import Data.Vector.Mutable++{-# INLINE casVectorElem #-}+-- | Perform a compare-and-swap on a single element of a mutable vector.+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++{-# INLINE unsafeCasVectorElem #-}+-- | Unsafe version of `casVectorElem` which is not bounds checked.+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++{-# INLINE readVectorElem #-}+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)++{-# INLINE unsafeReadVectorElem #-}+unsafeReadVectorElem :: IOVector a -> Int -> IO (Ticket a)+unsafeReadVectorElem (MVector st _ arr) ix = readArrayElem arr (st + ix)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Peter Fogg++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Peter Fogg nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ atomic-primops-vector.cabal view
@@ -0,0 +1,38 @@+-- Initial atomic-primops-vector.cabal generated by cabal init.  For +-- further documentation, see http://haskell.org/cabal/users-guide/++name:                atomic-primops-vector+version:             0.1.0.0+synopsis:            Atomic operations on Data.Vector types+-- description:         +license:             BSD3+license-file:        LICENSE+author:              Peter Fogg+maintainer:          peter.p.fogg@gmail.com+-- copyright:           +category:            Concurrency+build-type:          Simple+-- extra-source-files:  +cabal-version:       >=1.10++library+  exposed-modules: Data.Atomics.Vector+  -- other-modules:       +  -- other-extensions:    +  build-depends: base   >=4.8 && <4.9+               , vector >= 0.10 && < 0.11+               , atomic-primops >= 0.7 && < 0.8+               , primitive      >= 0.5 && < 0.6+  -- hs-source-dirs:+  ghc-options: -O2 -Wall+  default-language:    Haskell2010++Test-Suite test-atomic-primops-vector+    type:       exitcode-stdio-1.0+    hs-source-dirs: ./tests/+    main-is:    Main.hs+    build-depends: base   >=4.8 && <4.9+                 , vector >= 0.10 && < 0.11    +                 , atomic-primops-vector+    ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N4+    default-language:    Haskell2010
+ tests/Main.hs view
@@ -0,0 +1,20 @@++import Control.Monad+import Data.Vector+import Data.Vector.Mutable+import Data.Atomics.Vector++main :: IO ()+main = do+  v <- new 10 :: IO (IOVector Int)+  set v 0+  tik <- readVectorElem v 5+  casVectorElem v 5 tik 99+  v' <- unsafeFreeze v  +  print v'+--  assert+  unless (show v' == "fromList [0,0,0,0,0,99,0,0,0,0]")+    (error "Unexpected result!")++    +