4-- Module : Streamly.Atomics
5-- Copyright : (c) 2018-2019 Composewell Technologies
8-- Maintainer : harendra.kumar@gmail.com
9-- Stability : experimental
12module Streamly.Atomics
15 , atomicModifyIORefCAS_
21import Data.IORef (IORef, atomicModifyIORef)
23import Data.IORef (modifyIORef)
25import qualified Data.Atomics as A
30-- XXX Does it make sense to have replacements for atomicModifyIORef etc. on a
31-- single threaded system.
33-- Slightly faster version of CAS. Gained some improvement by avoiding the use
34-- of "evaluate" because we know we do not have exceptions in fn.
35{-# INLINE atomicModifyIORefCAS #-}
36atomicModifyIORefCAS :: IORef a -> (a -> (a,b)) -> IO b
37atomicModifyIORefCAS ref fn = do
38 tkt <- A.readForCAS ref
44 loop _ 0 = atomicModifyIORef ref fn
46 let (new, result) = fn $ A.peekTicket old
47 (success, tkt) <- A.casIORef ref old new
50 else loop tkt (tries - 1)
52{-# INLINE atomicModifyIORefCAS_ #-}
53atomicModifyIORefCAS_ :: IORef t -> (t -> t) -> IO ()
54atomicModifyIORefCAS_ = A.atomicModifyIORefCAS_
56{-# INLINE writeBarrier #-}
58writeBarrier = A.writeBarrier
60{-# INLINE storeLoadBarrier #-}
61storeLoadBarrier :: IO ()
62storeLoadBarrier = A.storeLoadBarrier
66{-# INLINE atomicModifyIORefCAS #-}
67atomicModifyIORefCAS :: IORef a -> (a -> (a,b)) -> IO b
68atomicModifyIORefCAS = atomicModifyIORef
70{-# INLINE atomicModifyIORefCAS_ #-}
71atomicModifyIORefCAS_ :: IORef a -> (a -> a) -> IO ()
72atomicModifyIORefCAS_ = modifyIORef
74{-# INLINE writeBarrier #-}
76writeBarrier = return ()
78{-# INLINE storeLoadBarrier #-}
79storeLoadBarrier :: IO ()
80storeLoadBarrier = 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