{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GLib.Unions.Mutex
(
Mutex(..) ,
newZeroMutex ,
#if defined(ENABLE_OVERLOADING)
ResolveMutexMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
MutexClearMethodInfo ,
#endif
mutexClear ,
#if defined(ENABLE_OVERLOADING)
MutexInitMethodInfo ,
#endif
mutexInit ,
#if defined(ENABLE_OVERLOADING)
MutexLockMethodInfo ,
#endif
mutexLock ,
#if defined(ENABLE_OVERLOADING)
MutexTrylockMethodInfo ,
#endif
mutexTrylock ,
#if defined(ENABLE_OVERLOADING)
MutexUnlockMethodInfo ,
#endif
mutexUnlock ,
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
newtype Mutex = Mutex (SP.ManagedPtr Mutex)
deriving (Mutex -> Mutex -> Bool
(Mutex -> Mutex -> Bool) -> (Mutex -> Mutex -> Bool) -> Eq Mutex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Mutex -> Mutex -> Bool
$c/= :: Mutex -> Mutex -> Bool
== :: Mutex -> Mutex -> Bool
$c== :: Mutex -> Mutex -> Bool
Eq)
instance SP.ManagedPtrNewtype Mutex where
toManagedPtr :: Mutex -> ManagedPtr Mutex
toManagedPtr (Mutex ManagedPtr Mutex
p) = ManagedPtr Mutex
p
instance BoxedPtr Mutex where
boxedPtrCopy :: Mutex -> IO Mutex
boxedPtrCopy = \Mutex
p -> Mutex -> (Ptr Mutex -> IO Mutex) -> IO Mutex
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Mutex
p (Int -> Ptr Mutex -> IO (Ptr Mutex)
forall a. (HasCallStack, CallocPtr a) => Int -> Ptr a -> IO (Ptr a)
copyBytes Int
8 (Ptr Mutex -> IO (Ptr Mutex))
-> (Ptr Mutex -> IO Mutex) -> Ptr Mutex -> IO Mutex
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (ManagedPtr Mutex -> Mutex) -> Ptr Mutex -> IO Mutex
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.wrapPtr ManagedPtr Mutex -> Mutex
Mutex)
boxedPtrFree :: Mutex -> IO ()
boxedPtrFree = \Mutex
x -> Mutex -> (Ptr Mutex -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
SP.withManagedPtr Mutex
x Ptr Mutex -> IO ()
forall a. Ptr a -> IO ()
SP.freeMem
instance CallocPtr Mutex where
boxedPtrCalloc :: IO (Ptr Mutex)
boxedPtrCalloc = Int -> IO (Ptr Mutex)
forall a. Int -> IO (Ptr a)
callocBytes Int
8
newZeroMutex :: MonadIO m => m Mutex
newZeroMutex :: m Mutex
newZeroMutex = IO Mutex -> m Mutex
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Mutex -> m Mutex) -> IO Mutex -> m Mutex
forall a b. (a -> b) -> a -> b
$ IO (Ptr Mutex)
forall a. CallocPtr a => IO (Ptr a)
boxedPtrCalloc IO (Ptr Mutex) -> (Ptr Mutex -> IO Mutex) -> IO Mutex
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr Mutex -> Mutex) -> Ptr Mutex -> IO Mutex
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr Mutex -> Mutex
Mutex
instance tag ~ 'AttrSet => Constructible Mutex tag where
new :: (ManagedPtr Mutex -> Mutex) -> [AttrOp Mutex tag] -> m Mutex
new ManagedPtr Mutex -> Mutex
_ [AttrOp Mutex tag]
attrs = do
Mutex
o <- m Mutex
forall (m :: * -> *). MonadIO m => m Mutex
newZeroMutex
Mutex -> [AttrOp Mutex 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set Mutex
o [AttrOp Mutex tag]
[AttrOp Mutex 'AttrSet]
attrs
Mutex -> m Mutex
forall (m :: * -> *) a. Monad m => a -> m a
return Mutex
o
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Mutex
type instance O.AttributeList Mutex = MutexAttributeList
type MutexAttributeList = ('[ ] :: [(Symbol, *)])
#endif
foreign import ccall "g_mutex_clear" g_mutex_clear ::
Ptr Mutex ->
IO ()
mutexClear ::
(B.CallStack.HasCallStack, MonadIO m) =>
Mutex
-> m ()
mutexClear :: Mutex -> m ()
mutexClear Mutex
mutex = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Mutex
mutex' <- Mutex -> IO (Ptr Mutex)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Mutex
mutex
Ptr Mutex -> IO ()
g_mutex_clear Ptr Mutex
mutex'
Mutex -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Mutex
mutex
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data MutexClearMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MutexClearMethodInfo Mutex signature where
overloadedMethod = mutexClear
#endif
foreign import ccall "g_mutex_init" g_mutex_init ::
Ptr Mutex ->
IO ()
mutexInit ::
(B.CallStack.HasCallStack, MonadIO m) =>
Mutex
-> m ()
mutexInit :: Mutex -> m ()
mutexInit Mutex
mutex = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Mutex
mutex' <- Mutex -> IO (Ptr Mutex)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Mutex
mutex
Ptr Mutex -> IO ()
g_mutex_init Ptr Mutex
mutex'
Mutex -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Mutex
mutex
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data MutexInitMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MutexInitMethodInfo Mutex signature where
overloadedMethod = mutexInit
#endif
foreign import ccall "g_mutex_lock" g_mutex_lock ::
Ptr Mutex ->
IO ()
mutexLock ::
(B.CallStack.HasCallStack, MonadIO m) =>
Mutex
-> m ()
mutexLock :: Mutex -> m ()
mutexLock Mutex
mutex = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Mutex
mutex' <- Mutex -> IO (Ptr Mutex)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Mutex
mutex
Ptr Mutex -> IO ()
g_mutex_lock Ptr Mutex
mutex'
Mutex -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Mutex
mutex
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data MutexLockMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MutexLockMethodInfo Mutex signature where
overloadedMethod = mutexLock
#endif
foreign import ccall "g_mutex_trylock" g_mutex_trylock ::
Ptr Mutex ->
IO CInt
mutexTrylock ::
(B.CallStack.HasCallStack, MonadIO m) =>
Mutex
-> m Bool
mutexTrylock :: Mutex -> m Bool
mutexTrylock Mutex
mutex = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
Ptr Mutex
mutex' <- Mutex -> IO (Ptr Mutex)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Mutex
mutex
CInt
result <- Ptr Mutex -> IO CInt
g_mutex_trylock Ptr Mutex
mutex'
let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
Mutex -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Mutex
mutex
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'
#if defined(ENABLE_OVERLOADING)
data MutexTrylockMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo MutexTrylockMethodInfo Mutex signature where
overloadedMethod = mutexTrylock
#endif
foreign import ccall "g_mutex_unlock" g_mutex_unlock ::
Ptr Mutex ->
IO ()
mutexUnlock ::
(B.CallStack.HasCallStack, MonadIO m) =>
Mutex
-> m ()
mutexUnlock :: Mutex -> m ()
mutexUnlock Mutex
mutex = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Mutex
mutex' <- Mutex -> IO (Ptr Mutex)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Mutex
mutex
Ptr Mutex -> IO ()
g_mutex_unlock Ptr Mutex
mutex'
Mutex -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Mutex
mutex
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data MutexUnlockMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MutexUnlockMethodInfo Mutex signature where
overloadedMethod = mutexUnlock
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveMutexMethod (t :: Symbol) (o :: *) :: * where
ResolveMutexMethod "clear" o = MutexClearMethodInfo
ResolveMutexMethod "init" o = MutexInitMethodInfo
ResolveMutexMethod "lock" o = MutexLockMethodInfo
ResolveMutexMethod "trylock" o = MutexTrylockMethodInfo
ResolveMutexMethod "unlock" o = MutexUnlockMethodInfo
ResolveMutexMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveMutexMethod t Mutex, O.MethodInfo info Mutex p) => OL.IsLabel t (Mutex -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif