2-- Module : Streamly.Internal.Data.Atomics
3-- Copyright : (c) 2018-2019 Composewell Technologies
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
10module Streamly.Internal.Data.Atomics
13 , atomicModifyIORefCAS_
19import Data.IORef (IORef, atomicModifyIORef)
21import Data.IORef (modifyIORef)
23import qualified Data.Atomics as A
28-- XXX Does it make sense to have replacements for atomicModifyIORef etc. on a
29-- single threaded system.
31-- Slightly faster version of CAS. Gained some improvement by avoiding the use
32-- of "evaluate" because we know we do not have exceptions in fn.
33{-# INLINE atomicModifyIORefCAS #-}
34atomicModifyIORefCAS :: IORef a -> (a -> (a,b)) -> IO b
35atomicModifyIORefCAS ref fn = do
36 tkt <- A.readForCAS ref
42 loop _ 0 = atomicModifyIORef ref fn
44 let (new, result) = fn $ A.peekTicket old
45 (success, tkt) <- A.casIORef ref old new
48 else loop tkt (tries - 1)
50{-# INLINE atomicModifyIORefCAS_ #-}
51atomicModifyIORefCAS_ :: IORef t -> (t -> t) -> IO ()
52atomicModifyIORefCAS_ = A.atomicModifyIORefCAS_
54{-# INLINE writeBarrier #-}
56writeBarrier = A.writeBarrier
58{-# INLINE storeLoadBarrier #-}
59storeLoadBarrier :: IO ()
60storeLoadBarrier = A.storeLoadBarrier
64{-# INLINE atomicModifyIORefCAS #-}
65atomicModifyIORefCAS :: IORef a -> (a -> (a,b)) -> IO b
66atomicModifyIORefCAS = atomicModifyIORef
68{-# INLINE atomicModifyIORefCAS_ #-}
69atomicModifyIORefCAS_ :: IORef a -> (a -> a) -> IO ()
70atomicModifyIORefCAS_ = modifyIORef
72{-# INLINE writeBarrier #-}
74writeBarrier = return ()
76{-# INLINE storeLoadBarrier #-}
77storeLoadBarrier :: IO ()
78storeLoadBarrier = 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