{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

The #GThread struct represents a running thread. This struct
is returned by g_thread_new() or g_thread_try_new(). You can
obtain the #GThread struct representing the current thread by
calling g_thread_self().

GThread is refcounted, see g_thread_ref() and g_thread_unref().
The thread represented by it holds a reference while it is running,
and g_thread_join() consumes the reference that it is given, so
it is normally not necessary to manage GThread references
explicitly.

The structure is opaque -- none of its fields may be directly
accessed.
-}

module GI.GLib.Structs.Thread
    ( 

-- * Exported types
    Thread(..)                              ,
    noThread                                ,


 -- * Methods
-- ** threadRef
    threadRef                               ,


-- ** threadUnref
    threadUnref                             ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.GLib.Types
import GI.GLib.Callbacks

newtype Thread = Thread (ForeignPtr Thread)
foreign import ccall "g_thread_get_type" c_g_thread_get_type :: 
    IO GType

instance BoxedObject Thread where
    boxedType _ = c_g_thread_get_type

noThread :: Maybe Thread
noThread = Nothing

-- method Thread::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Thread", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Thread", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GLib" "Thread"
-- throws : False
-- Skip return : False

foreign import ccall "g_thread_ref" g_thread_ref :: 
    Ptr Thread ->                           -- _obj : TInterface "GLib" "Thread"
    IO (Ptr Thread)


threadRef ::
    (MonadIO m) =>
    Thread ->                               -- _obj
    m Thread
threadRef _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_thread_ref _obj'
    checkUnexpectedReturnNULL "g_thread_ref" result
    result' <- (wrapBoxed Thread) result
    touchManagedPtr _obj
    return result'

-- method Thread::unref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Thread", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Thread", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_thread_unref" g_thread_unref :: 
    Ptr Thread ->                           -- _obj : TInterface "GLib" "Thread"
    IO ()


threadUnref ::
    (MonadIO m) =>
    Thread ->                               -- _obj
    m ()
threadUnref _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_thread_unref _obj'
    touchManagedPtr _obj
    return ()