1{-# OPTIONS_HADDOCK hide #-}
5-- Module : Streamly.Internal.Data.Atomics
6-- Copyright : (c) 2018-2019 Composewell Technologies
9-- Maintainer : streamly@composewell.com
10-- Stability : experimental
13module Streamly.Internal.Data.Atomics
16 , atomicModifyIORefCAS_
22import Data.IORef (IORef, atomicModifyIORef)
24import Data.IORef (modifyIORef)
26import qualified Data.Atomics as A
31-- XXX Does it make sense to have replacements for atomicModifyIORef etc. on a
32-- single threaded system.
34-- Slightly faster version of CAS. Gained some improvement by avoiding the use
35-- of "evaluate" because we know we do not have exceptions in fn.
36{-# INLINE atomicModifyIORefCAS #-}
37atomicModifyIORefCAS :: IORef a -> (a -> (a,b)) -> IO b
38atomicModifyIORefCAS ref fn = do
39 tkt <- A.readForCAS ref
45 loop _ 0 = atomicModifyIORef ref fn
47 let (new, result) = fn $ A.peekTicket old
48 (success, tkt) <- A.casIORef ref old new
51 else loop tkt (tries - 1)
53{-# INLINE atomicModifyIORefCAS_ #-}
54atomicModifyIORefCAS_ :: IORef t -> (t -> t) -> IO ()
55atomicModifyIORefCAS_ = A.atomicModifyIORefCAS_
57{-# INLINE writeBarrier #-}
59writeBarrier = A.writeBarrier
61{-# INLINE storeLoadBarrier #-}
62storeLoadBarrier :: IO ()
63storeLoadBarrier = A.storeLoadBarrier
67{-# INLINE atomicModifyIORefCAS #-}
68atomicModifyIORefCAS :: IORef a -> (a -> (a,b)) -> IO b
69atomicModifyIORefCAS = atomicModifyIORef
71{-# INLINE atomicModifyIORefCAS_ #-}
72atomicModifyIORefCAS_ :: IORef a -> (a -> a) -> IO ()
73atomicModifyIORefCAS_ = modifyIORef
75{-# INLINE writeBarrier #-}
77writeBarrier = return ()
79{-# INLINE storeLoadBarrier #-}
80storeLoadBarrier :: IO ()
81storeLoadBarrier = return ()
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list