{-# 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 ,
noMutex ,
#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.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 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 (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 WrappedPtr Mutex where
wrappedPtrCalloc :: IO (Ptr Mutex)
wrappedPtrCalloc = Int -> IO (Ptr Mutex)
forall a. Int -> IO (Ptr a)
callocBytes 8
wrappedPtrCopy :: Mutex -> IO Mutex
wrappedPtrCopy = \p :: Mutex
p -> Mutex -> (Ptr Mutex -> IO Mutex) -> IO Mutex
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Mutex
p (Int -> Ptr Mutex -> IO (Ptr Mutex)
forall a. WrappedPtr a => Int -> Ptr a -> IO (Ptr a)
copyBytes 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, WrappedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr Mutex -> Mutex
Mutex)
wrappedPtrFree :: Maybe (GDestroyNotify Mutex)
wrappedPtrFree = GDestroyNotify Mutex -> Maybe (GDestroyNotify Mutex)
forall a. a -> Maybe a
Just GDestroyNotify Mutex
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free
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. WrappedPtr a => IO (Ptr a)
wrappedPtrCalloc 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, WrappedPtr 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 _ attrs :: [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
noMutex :: Maybe Mutex
noMutex :: Maybe Mutex
noMutex = Maybe Mutex
forall a. Maybe a
Nothing
#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
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
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
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
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
/= 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
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