{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GLib.Structs.Thread
(
Thread(..) ,
#if defined(ENABLE_OVERLOADING)
ResolveThreadMethod ,
#endif
threadErrorQuark ,
threadExit ,
#if defined(ENABLE_OVERLOADING)
ThreadJoinMethodInfo ,
#endif
threadJoin ,
#if defined(ENABLE_OVERLOADING)
ThreadRefMethodInfo ,
#endif
threadRef ,
threadSelf ,
#if defined(ENABLE_OVERLOADING)
ThreadUnrefMethodInfo ,
#endif
threadUnref ,
threadYield ,
) 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 Thread = Thread (SP.ManagedPtr Thread)
deriving (Thread -> Thread -> Bool
(Thread -> Thread -> Bool)
-> (Thread -> Thread -> Bool) -> Eq Thread
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Thread -> Thread -> Bool
$c/= :: Thread -> Thread -> Bool
== :: Thread -> Thread -> Bool
$c== :: Thread -> Thread -> Bool
Eq)
instance SP.ManagedPtrNewtype Thread where
toManagedPtr :: Thread -> ManagedPtr Thread
toManagedPtr (Thread ManagedPtr Thread
p) = ManagedPtr Thread
p
foreign import ccall "g_thread_get_type" c_g_thread_get_type ::
IO GType
type instance O.ParentTypes Thread = '[]
instance O.HasParentTypes Thread
instance B.Types.TypedObject Thread where
glibType :: IO GType
glibType = IO GType
c_g_thread_get_type
instance B.Types.GBoxed Thread
instance B.GValue.IsGValue Thread where
toGValue :: Thread -> IO GValue
toGValue Thread
o = do
GType
gtype <- IO GType
c_g_thread_get_type
Thread -> (Ptr Thread -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Thread
o (GType -> (GValue -> Ptr Thread -> IO ()) -> Ptr Thread -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Thread -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
fromGValue :: GValue -> IO Thread
fromGValue GValue
gv = do
Ptr Thread
ptr <- GValue -> IO (Ptr Thread)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr Thread)
(ManagedPtr Thread -> Thread) -> Ptr Thread -> IO Thread
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr Thread -> Thread
Thread Ptr Thread
ptr
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Thread
type instance O.AttributeList Thread = ThreadAttributeList
type ThreadAttributeList = ('[ ] :: [(Symbol, *)])
#endif
foreign import ccall "g_thread_join" g_thread_join ::
Ptr Thread ->
IO (Ptr ())
threadJoin ::
(B.CallStack.HasCallStack, MonadIO m) =>
Thread
-> m (Ptr ())
threadJoin :: Thread -> m (Ptr ())
threadJoin Thread
thread = IO (Ptr ()) -> m (Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ do
Ptr Thread
thread' <- Thread -> IO (Ptr Thread)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Thread
thread
Ptr ()
result <- Ptr Thread -> IO (Ptr ())
g_thread_join Ptr Thread
thread'
Thread -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Thread
thread
Ptr () -> IO (Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
result
#if defined(ENABLE_OVERLOADING)
data ThreadJoinMethodInfo
instance (signature ~ (m (Ptr ())), MonadIO m) => O.MethodInfo ThreadJoinMethodInfo Thread signature where
overloadedMethod = threadJoin
#endif
foreign import ccall "g_thread_ref" g_thread_ref ::
Ptr Thread ->
IO (Ptr Thread)
threadRef ::
(B.CallStack.HasCallStack, MonadIO m) =>
Thread
-> m Thread
threadRef :: Thread -> m Thread
threadRef Thread
thread = IO Thread -> m Thread
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Thread -> m Thread) -> IO Thread -> m Thread
forall a b. (a -> b) -> a -> b
$ do
Ptr Thread
thread' <- Thread -> IO (Ptr Thread)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Thread
thread
Ptr Thread
result <- Ptr Thread -> IO (Ptr Thread)
g_thread_ref Ptr Thread
thread'
Text -> Ptr Thread -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"threadRef" Ptr Thread
result
Thread
result' <- ((ManagedPtr Thread -> Thread) -> Ptr Thread -> IO Thread
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Thread -> Thread
Thread) Ptr Thread
result
Thread -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Thread
thread
Thread -> IO Thread
forall (m :: * -> *) a. Monad m => a -> m a
return Thread
result'
#if defined(ENABLE_OVERLOADING)
data ThreadRefMethodInfo
instance (signature ~ (m Thread), MonadIO m) => O.MethodInfo ThreadRefMethodInfo Thread signature where
overloadedMethod = threadRef
#endif
foreign import ccall "g_thread_unref" g_thread_unref ::
Ptr Thread ->
IO ()
threadUnref ::
(B.CallStack.HasCallStack, MonadIO m) =>
Thread
-> m ()
threadUnref :: Thread -> m ()
threadUnref Thread
thread = 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 Thread
thread' <- Thread -> IO (Ptr Thread)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Thread
thread
Ptr Thread -> IO ()
g_thread_unref Ptr Thread
thread'
Thread -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Thread
thread
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data ThreadUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo ThreadUnrefMethodInfo Thread signature where
overloadedMethod = threadUnref
#endif
foreign import ccall "g_thread_error_quark" g_thread_error_quark ::
IO Word32
threadErrorQuark ::
(B.CallStack.HasCallStack, MonadIO m) =>
m Word32
threadErrorQuark :: m Word32
threadErrorQuark = IO Word32 -> m Word32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Word32 -> m Word32) -> IO Word32 -> m Word32
forall a b. (a -> b) -> a -> b
$ do
Word32
result <- IO Word32
g_thread_error_quark
Word32 -> IO Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
result
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "g_thread_exit" g_thread_exit ::
Ptr () ->
IO ()
threadExit ::
(B.CallStack.HasCallStack, MonadIO m) =>
Ptr ()
-> m ()
threadExit :: Ptr () -> m ()
threadExit Ptr ()
retval = 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 () -> IO ()
g_thread_exit Ptr ()
retval
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "g_thread_self" g_thread_self ::
IO (Ptr Thread)
threadSelf ::
(B.CallStack.HasCallStack, MonadIO m) =>
m Thread
threadSelf :: m Thread
threadSelf = IO Thread -> m Thread
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Thread -> m Thread) -> IO Thread -> m Thread
forall a b. (a -> b) -> a -> b
$ do
Ptr Thread
result <- IO (Ptr Thread)
g_thread_self
Text -> Ptr Thread -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"threadSelf" Ptr Thread
result
Thread
result' <- ((ManagedPtr Thread -> Thread) -> Ptr Thread -> IO Thread
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Thread -> Thread
Thread) Ptr Thread
result
Thread -> IO Thread
forall (m :: * -> *) a. Monad m => a -> m a
return Thread
result'
#if defined(ENABLE_OVERLOADING)
#endif
foreign import ccall "g_thread_yield" g_thread_yield ::
IO ()
threadYield ::
(B.CallStack.HasCallStack, MonadIO m) =>
m ()
threadYield :: m ()
threadYield = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
IO ()
g_thread_yield
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveThreadMethod (t :: Symbol) (o :: *) :: * where
ResolveThreadMethod "join" o = ThreadJoinMethodInfo
ResolveThreadMethod "ref" o = ThreadRefMethodInfo
ResolveThreadMethod "unref" o = ThreadUnrefMethodInfo
ResolveThreadMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveThreadMethod t Thread, O.MethodInfo info Thread p) => OL.IsLabel t (Thread -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif