gi-gtk-hs-0.3.18: A wrapper for gi-gtk, adding a few more idiomatic API parts on top

Stability | provisional
Portability | portable (depends on GHC)
Safe Haskell | None
Language | Haskell2010

Data.GI.Gtk.Threading

Description

Utility functions for threading

Synopsis

- setGUIThread :: Thread -> IO ()
- getGUIThread :: IO (Maybe Thread)
- setCurrentThreadAsGUIThread :: IO ()
- postGUISyncWithPriority :: Int32 -> IO a -> IO a
- postGUISync :: IO a -> IO a
- postGUIASyncWithPriority :: Int32 -> IO () -> IO ()
- postGUIASync :: IO () -> IO ()
- compareThreads :: Thread -> Thread -> IO Bool
- isGUIThread :: IO Bool
- newtype Thread = Thread (ManagedPtr Thread)
- threadSelf :: (HasCallStack, MonadIO m) => m Thread

# Documentation

Utility functions to run IO actions on the GUI thread. You must call `setGUIThread` or `setCurrentThreadAsGUIThread` before using the synchronous options, or you risk deadlocking.

Note that the notion of Thread used by this module corresponds to operating system threads, not Haskell threads. A single operating system thread may run multiple Haskell threads, and a Haskell thread may migrate between operating system threads. In order for this nothing of Thread to make sense to a Haskell program, we must be working in a bound Haskell thread, which is tied to a single operating system thread. Haskell's main function is automatically bound, and the postGUI functions will create a new bound thread if nessasary.

setGUIThread :: Thread -> IO () Source #

Inform gi-gtk-hs what thread is running the gtk main loop.

getGUIThread :: IO (Maybe Thread) Source #

Get the Thread that is running the Gtk main loop, if it has been set.

setCurrentThreadAsGUIThread :: IO () Source #

Inform gi-gtk-hs that the current thread is, or will be, running the gtk main loop.

Equivalent to ``threadSelf` >>= `setGUIThread``

postGUISyncWithPriority :: Int32 -> IO a -> IO a Source #

Queue an action to be run in the GTK event loop. If called from the same process as the event loop, this runs the action directly. Otherwise, this queues it in GTK's event loop and blocks until the action is complete

You must call `setGUIThread` or `setCurrentThreadAsGUIThread` before this.

Priority is typically between `PRIORITY_HIGH_IDLE` (100) and `PRIORITY_DEFAULT_IDLE` (200)

postGUISync :: IO a -> IO a Source #

Queue an action to be run in the GTK event loop. If called from the same process as the event loop, this runs the action directly. Otherwise, this queues it in GTK's event loop and blocks until the action is complete

You must call `setGUIThread` or `setCurrentThreadAsGUIThread` before this.

Equivalent to ``postGUISyncWithPriority` `PRIORITY_DEFAULT_IDLE``

postGUIASyncWithPriority :: Int32 -> IO () -> IO () Source #

Queue an action to be run in the GTK event loop. This function queues the event regardless of what process it is called from, and returns immidietly.

Priority is typically between `PRIORITY_HIGH_IDLE` (100) and `PRIORITY_DEFAULT_IDLE` (200)

postGUIASync :: IO () -> IO () Source #

Queue an action to be run in the GTK event loop. This function queues the event regardless of what process it is called from, and returns immidietly.

Equivalent to ``postGUIASyncWithPriority` `PRIORITY_DEFAULT_IDLE``

compareThreads :: Thread -> Thread -> IO Bool Source #

Test if two `Thread`s refer to the same OS thread. A `Thread` can be gotten from `threadSelf`. Note that `threadSelf` only makes sense from a bound thread.

isGUIThread :: IO Bool Source #

Check if the current thread is the Gtk gui thread.

You must call `setGUIThread` or `setCurrentThreadAsGUIThread` before this. This only makes sense when called from a bound thread.

newtype Thread Source #

Memory-managed wrapper type.

Constructors

Thread (ManagedPtr Thread) |

#### Instances

Instances details

Eq Thread |
Instance details Defined in GI.GLib.Structs.Thread Methods (==) :: Thread -> Thread -> Bool Source # (/=) :: Thread -> Thread -> Bool Source #
GBoxed Thread |
Instance details Defined in GI.GLib.Structs.Thread
ManagedPtrNewtype Thread |
Instance details Defined in GI.GLib.Structs.Thread Methods toManagedPtr :: Thread -> ManagedPtr Thread Source #
TypedObject Thread |
Instance details Defined in GI.GLib.Structs.Thread Methods glibType :: IO GType Source #
HasParentTypes Thread |
Instance details Defined in GI.GLib.Structs.Thread
tag ~ 'AttrSet => Constructible Thread tag |
Instance details Defined in GI.GLib.Structs.Thread Methods new :: MonadIO m => (ManagedPtr Thread -> Thread) -> [AttrOp Thread tag] -> m Thread Source #
HasAttributeList Thread |
Instance details Defined in GI.GLib.Structs.Thread
(info ~ ResolveThreadMethod t Thread, OverloadedMethod info Thread p, HasField t Thread p) => HasField (t :: Symbol) Thread p |
Instance details Defined in GI.GLib.Structs.Thread Methods getField :: Thread -> p Source #
(signature ~ m Text, MonadIO m) => OverloadedMethod ThreadGetNameMethodInfo Thread signature |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethod :: Thread -> signature Source #
(signature ~ m (Ptr ()), MonadIO m) => OverloadedMethod ThreadJoinMethodInfo Thread signature |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethod :: Thread -> signature Source #
(signature ~ m Thread, MonadIO m) => OverloadedMethod ThreadRefMethodInfo Thread signature |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethod :: Thread -> signature Source #
(signature ~ m (), MonadIO m) => OverloadedMethod ThreadUnrefMethodInfo Thread signature |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethod :: Thread -> signature Source #
OverloadedMethodInfo ThreadGetNameMethodInfo Thread |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethodInfo :: Maybe ResolvedSymbolInfo Source #
OverloadedMethodInfo ThreadJoinMethodInfo Thread |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethodInfo :: Maybe ResolvedSymbolInfo Source #
OverloadedMethodInfo ThreadRefMethodInfo Thread |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethodInfo :: Maybe ResolvedSymbolInfo Source #
OverloadedMethodInfo ThreadUnrefMethodInfo Thread |
Instance details Defined in GI.GLib.Structs.Thread Methods overloadedMethodInfo :: Maybe ResolvedSymbolInfo Source #
(info ~ ResolveThreadMethod t Thread, OverloadedMethodInfo info Thread) => IsLabel t (MethodProxy info Thread) |
Instance details Defined in GI.GLib.Structs.Thread Methods fromLabel :: MethodProxy info Thread Source #
(info ~ ResolveThreadMethod t Thread, OverloadedMethod info Thread p) => IsLabel t (Thread -> p) |
Instance details Defined in GI.GLib.Structs.Thread Methods fromLabel :: Thread -> p Source #
IsGValue (Maybe Thread) | Convert `Thread` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.GLib.Structs.Thread Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe Thread -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe Thread) Source #
type AttributeList Thread |
Instance details Defined in GI.GLib.Structs.Thread type AttributeList Thread = ThreadAttributeList
type ParentTypes Thread |
Instance details Defined in GI.GLib.Structs.Thread type ParentTypes Thread = '[] :: [Type]

threadSelf Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m Thread | Returns: the `Thread` representing the current thread

This function returns the `Thread` corresponding to the current thread. Note that this function does not increase the reference count of the returned struct.

This function will return a `Thread` even for threads that were not created by GLib (i.e. those created by other threading APIs). This may be useful for thread identification purposes (i.e. comparisons) but you must not use GLib functions (such as `threadJoin`) on these threads.