{-# LANGUAGE CPP, TypeSynonymInstances, BangPatterns #-}
{-# LANGUAGE ForeignFunctionInterface, GHCForeignImportPrim, MagicHash, UnboxedTuples, UnliftedFFITypes #-}
#define CASTFUN
module Data.Atomics.Internal
(
casIntArray#, fetchAddIntArray#,
readForCAS#, casMutVarTicketed#, casArrayTicketed#,
Ticket,
ptrEq
)
where
import GHC.Exts (Int(I#), Any, RealWorld, Int#, State#, MutableArray#, MutVar#,
unsafeCoerce#, reallyUnsafePtrEquality#,
casArray#, casIntArray#, fetchAddIntArray#, readMutVar#, casMutVar#)
#ifdef DEBUG_ATOMICS
{-# NOINLINE readForCAS# #-}
{-# NOINLINE casMutVarTicketed# #-}
{-# NOINLINE casArrayTicketed# #-}
#else
{-# INLINE casArrayTicketed# #-}
#endif
casArrayTicketed# :: MutableArray# RealWorld a -> Int# -> Ticket a -> Ticket a
-> State# RealWorld -> (# State# RealWorld, Int#, Ticket a #)
casArrayTicketed# :: forall a.
MutableArray# RealWorld a
-> Int#
-> Ticket a
-> Ticket a
-> State# RealWorld
-> (# State# RealWorld, Int#, Ticket a #)
casArrayTicketed# = (MutableArray# Any Any
-> Int# -> Any -> Any -> State# Any -> (# State# Any, Int#, Any #))
-> MutableArray# RealWorld a
-> Int#
-> Ticket a
-> Ticket a
-> State# RealWorld
-> (# State# RealWorld, Int#, Ticket a #)
forall a b. a -> b
unsafeCoerce# MutableArray# Any Any
-> Int# -> Any -> Any -> State# Any -> (# State# Any, Int#, Any #)
forall d a.
MutableArray# d a
-> Int# -> a -> a -> State# d -> (# State# d, Int#, a #)
casArray#
newtype Ticket a = Ticket Any
instance Show (Ticket a) where
show :: Ticket a -> String
show Ticket a
_ = String
"<CAS_ticket>"
{-# NOINLINE ptrEq #-}
ptrEq :: a -> a -> Bool
ptrEq :: forall a. a -> a -> Bool
ptrEq !a
x !a
y = Int# -> Int
I# (a -> a -> Int#
forall a b. a -> b -> Int#
reallyUnsafePtrEquality# a
x a
y) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
instance Eq (Ticket a) where
== :: Ticket a -> Ticket a -> Bool
(==) = Ticket a -> Ticket a -> Bool
forall a. a -> a -> Bool
ptrEq
readForCAS# :: MutVar# RealWorld a ->
State# RealWorld -> (# State# RealWorld, Ticket a #)
#ifdef CASTFUN
readForCAS# :: forall a.
MutVar# RealWorld a
-> State# RealWorld -> (# State# RealWorld, Ticket a #)
readForCAS# = (MutVar# Any Any -> State# Any -> (# State# Any, Any #))
-> MutVar# RealWorld a
-> State# RealWorld
-> (# State# RealWorld, Ticket a #)
forall a b. a -> b
unsafeCoerce# MutVar# Any Any -> State# Any -> (# State# Any, Any #)
forall d a. MutVar# d a -> State# d -> (# State# d, a #)
readMutVar#
#else
readForCAS# mv rw =
case readMutVar# mv rw of
(# rw', a #) -> (# rw', unsafeCoerce# a #)
#endif
casMutVarTicketed# :: MutVar# RealWorld a -> Ticket a -> Ticket a ->
State# RealWorld -> (# State# RealWorld, Int#, Ticket a #)
casMutVarTicketed# :: forall a.
MutVar# RealWorld a
-> Ticket a
-> Ticket a
-> State# RealWorld
-> (# State# RealWorld, Int#, Ticket a #)
casMutVarTicketed# = (MutVar# Any Any
-> Any -> Any -> State# Any -> (# State# Any, Int#, Any #))
-> MutVar# RealWorld a
-> Ticket a
-> Ticket a
-> State# RealWorld
-> (# State# RealWorld, Int#, Ticket a #)
forall a b. a -> b
unsafeCoerce# MutVar# Any Any
-> Any -> Any -> State# Any -> (# State# Any, Int#, Any #)
forall d a.
MutVar# d a -> a -> a -> State# d -> (# State# d, Int#, a #)
casMutVar#