W Wrapl, The Programming Language

Libraries:Gtk:Glib:GMainContext

Types

T

Constants

Nil : T

Functions

Default() : Gtk.Glib.GMainContext.T

Returns the global default main context. This is the main context used for main loop functions when a main loop is not explicitly specified, and corresponds to the "main" main loop. See also Gtk.Glib.GMain.ContextGetThreadDefault.

Returns the global default main context. [transfer none]


GetThreadDefault() : Gtk.Glib.GMainContext.T

Gets the thread-default T for this thread. Asynchronous operations that want to be able to be run in contexts other than the default one should call this method to get a T to add their Gtk.Glib.GSource.Ts to. (Note that even in single-threaded programs applications may sometimes want to temporarily push a non-default context, so it is not safe to assume that this will always return NULL if threads are not initialized.)

Returns the thread-default T, or NULL if the thread-default context is the global default context. [transfer none]


New() : Gtk.Glib.GMainContext.T

Creates a new T structure.

Returns the new T


Methods

:"="(_ @ T, _ @ T)

:Acquire(self @ T) : Std.Symbol.T

Tries to become the owner of the specified context. If some other thread is the owner of the context, returns FALSE immediately. Ownership is properly recursive: the owner can require ownership again and will release ownership when Gtk.Glib.GMain.ContextRelease is called as many times as Gtk.Glib.GMain.ContextAcquire.

You must be the owner of a context before you can call Gtk.Glib.GMain.ContextPrepare, Gtk.Glib.GMain.ContextQuery, Gtk.Glib.GMain.ContextCheck, Gtk.Glib.GMain.ContextDispatch.

context a T
Returns TRUE if the operation succeeded, and this thread is now the owner of context.


:AddPoll(self @ T, fd @ Std.Object.T, priority @ Std.Integer.SmallT) : Std.Object.T

Adds a file descriptor to the set of file descriptors polled for this context. This will very seldom be used directly. Instead a typical event source will use Gtk.Glib.GMain.SourceAddPoll instead.

context a T (or NULL for the default context)
fd a GPollFD structure holding information about a file descriptor to watch.
priority the priority for this file descriptor which should be the same as the priority used for Gtk.Glib.GMain.SourceAttach to ensure that the file descriptor is polled whenever the results may be needed.


:Check(self @ T, max_priority @ Std.Integer.SmallT, fds @ Std.Object.T, n_fds @ Std.Integer.SmallT) : Std.Integer.SmallT

Passes the results of polling back to the main loop.

context a T
max_priority the maximum numerical priority of sources to check
fds array of GPollFD's that was passed to the last call to Gtk.Glib.GMain.ContextQuery. [array length=n_fds]
n_fds return value of Gtk.Glib.GMain.ContextQuery
Returns TRUE if some sources are ready to be dispatched.


:Dispatch(self @ T) : Std.Object.T

Dispatches all pending sources.

context a T


:FindSourceByFuncsUserData(self @ T, funcs @ Gtk.Glib.GSourceFuncs.T, user_data) : Gtk.Glib.GSource.T

Finds a source with the given source functions and user data. If multiple sources exist with the same source function and user data, the first one found will be returned.

context a T (if NULL, the default context will be used).
funcs the source_funcs passed to Gtk.Glib.GMain.SourceNew.
user_data the user data from the callback.
Returns the source, if one was found, otherwise NULL. [transfer none]


:FindSourceById(self @ T, source_id @ Std.Integer.SmallT) : Gtk.Glib.GSource.T

Finds a Gtk.Glib.GSource.T given a pair of context and ID.

context a T (if NULL, the default context will be used)
source_id the source ID, as returned by Gtk.Glib.GMain.SourceGetId.
Returns the Gtk.Glib.GSource.T if found, otherwise, NULL. [transfer none]


:FindSourceByUserData(self @ T, user_data) : Gtk.Glib.GSource.T

Finds a source with the given user data for the callback. If multiple sources exist with the same user data, the first one found will be returned.

context a T
user_data the user_data for the callback.
Returns the source, if one was found, otherwise NULL. [transfer none]


:GetPollFunc(self @ T) : Std.Object.T

Gets the poll function set by Gtk.Glib.GMain.ContextSetPollFunc.

context a T
Returns the poll function


:Invoke(self @ T, function @ Std.Function.T, data @ Std.Address.T) : Std.Object.T

Invokes a function in such a way that context is owned during the invocation of function.

If context is NULL then the global default main context - as returned by Gtk.Glib.GMain.ContextDefault - is used.

If context is owned by the current thread, function is called directly. Otherwise, if context is the thread-default main context of the current thread and Gtk.Glib.GMain.ContextAcquire succeeds, then function is called and Gtk.Glib.GMain.ContextRelease is called afterwards.

In any other case, an idle source is created to call function and that source is attached to context (presumably to be run in another thread). The idle source is attached with G_PRIORITY_DEFAULT priority. If you want a different priority, use Gtk.Glib.GMain.ContextInvokeFull.

Note that, as with normal idle functions, function should probably return FALSE. If it returns TRUE, it will be continuously run in a loop (and may prevent this call from returning).

context a T, or NULL. [allow-none]
function function to call
data data to pass to function


:InvokeFull(self @ T, priority @ Std.Integer.SmallT, function @ Std.Function.T, data @ Std.Address.T, notify @ Std.Function.T) : Std.Object.T

Invokes a function in such a way that context is owned during the invocation of function.

This function is the same as Gtk.Glib.GMain.ContextInvoke except that it lets you specify the priority incase function ends up being scheduled as an idle and also lets you give a Gtk.Glib.GDestroyNotify for data.

notify should not assume that it is called from any particular thread or with any particular context acquired.

context a T, or NULL. [allow-none]
priority the priority at which to run function
function function to call
data data to pass to function
notify a function to call when data is no longer in use, or NULL.


:IsOwner(self @ T) : Std.Symbol.T

Determines whether this thread holds the (recursive) ownership of this T. This is useful to know before waiting on another thread that may be blocking to get ownership of context.

context a T
Returns TRUE if current thread is owner of context.


:Iteration(self @ T, may_block @ Std.Symbol.T) : Std.Symbol.T

Runs a single iteration for the given main loop. This involves checking to see if any event sources are ready to be processed, then if no events sources are ready and may_block is TRUE, waiting for a source to become ready, then dispatching the highest priority events sources that are ready. Otherwise, if may_block is FALSE sources are not waited to become ready, only those highest priority events sources will be dispatched (if any), that are ready at this given moment without further waiting.

Note that even when may_block is TRUE, it is still possible for Gtk.Glib.GMain.ContextIteration to return FALSE, since the the wait may be interrupted for other reasons than an event source becoming ready.

context a T (if NULL, the default context will be used)
may_block whether the call may block.
Returns TRUE if events were dispatched.


:Pending(self @ T) : Std.Symbol.T

Checks if any sources have pending events for the given context.

context a T (if NULL, the default context will be used)
Returns TRUE if events are pending.


:PopThreadDefault(self @ T) : Std.Object.T

Pops context off the thread-default context stack (verifying that it was on the top of the stack).

context a T object, or NULL


:Prepare(self @ T, priority @ Std.Object.T) : Std.Symbol.T

Prepares to poll sources within a main loop. The resulting information for polling is determined by calling Gtk.Glib.GMain.ContextQuery.

context a T
priority location to store priority of highest priority source already ready.
Returns TRUE if some source is ready to be dispatched prior to polling.


:PushThreadDefault(self @ T) : Std.Object.T

Acquires context and sets it as the thread-default context for the current thread. This will cause certain asynchronous operations (such as most gio-based I/O) which are started in this thread to run under context and deliver their results to its main loop, rather than running under the global default context in the main thread. Note that calling this function changes the context returned by Gtk.Glib.GMain.ContextGetThreadDefault, not the one returned by Gtk.Glib.GMain.ContextDefault, so it does not affect the context used by functions like Gtk.Glib.GMain.IdleAdd.

Normally you would call this function shortly after creating a new thread, passing it a T which will be run by a Gtk.Glib.GMainLoop.T in that thread, to set a new default context for all async operations in that thread. (In this case, you don't need to ever call Gtk.Glib.GMain.ContextPopThreadDefault.) In some cases however, you may want to schedule a single operation in a non-default context, or temporarily use a non-default context in the main thread. In that case, you can wrap the call to the asynchronous operation inside a Gtk.Glib.GMain.ContextPushThreadDefault / Gtk.Glib.GMain.ContextPopThreadDefault pair, but it is up to you to ensure that no other asynchronous operations accidentally get started while the non-default context is active.

Beware that libraries that predate this function may not correctly handle being used from a thread with a thread-default context. Eg, see Gtk.Gio.GFile.SupportsThreadContexts.

context a T, or NULL for the global default context


:Query(self @ T, max_priority @ Std.Integer.SmallT, timeout_ @ Std.Object.T, fds @ Std.Object.T, n_fds @ Std.Integer.SmallT) : Std.Integer.SmallT

Determines information necessary to poll this main loop.

context a T
max_priority maximum priority source to check
timeout_ location to store timeout to be used in polling. [out]
fds location to store GPollFD records that need to be polled. [out caller-allocates][array length=n_fds]
n_fds length of fds.
Returns the number of records actually stored in fds, or, if more than n_fds records need to be stored, the number of records that need to be stored.


:Ref(self @ T) : Gtk.Glib.GMainContext.T

Increases the reference count on a T object by one.

context a T
Returns the context that was passed in (since 2.6)


:Release(self @ T) : Std.Object.T

Releases ownership of a context previously acquired by this thread with Gtk.Glib.GMain.ContextAcquire. If the context was acquired multiple times, the ownership will be released only when Gtk.Glib.GMain.ContextRelease is called as many times as it was acquired.

context a T


:RemovePoll(self @ T, fd @ Std.Object.T) : Std.Object.T

Removes file descriptor from the set of file descriptors to be polled for a particular context.

context a T
fd a GPollFD descriptor previously added with Gtk.Glib.GMain.ContextAddPoll


:SetPollFunc(self @ T, func @ Std.Object.T) : Std.Object.T

Sets the function to use to handle polling of file descriptors. It will be used instead of the poll() system call (or GLib's replacement function, which is used where poll() isn't available).

This function could possibly be used to integrate the GLib event loop with an external event loop.

context a T
func the function to call to poll all file descriptors


:Unref(self @ T) : Std.Object.T

Decreases the reference count on a T object by one. If the result is zero, free the context and free all associated memory.

context a T


:Wait(self @ T, cond @ Gtk.Glib.GCond.T, mutex @ Gtk.Glib.GMutex.T) : Std.Symbol.T

Tries to become the owner of the specified context, as with Gtk.Glib.GMain.ContextAcquire. But if another thread is the owner, atomically drop mutex and wait on cond until that owner releases ownership or until cond is signaled, then try again (once) to become the owner.

context a T
cond a condition variable
mutex a mutex, currently held
Returns TRUE if the operation succeeded, and this thread is now the owner of context.


:Wakeup(self @ T) : Std.Object.T

If context is currently waiting in a poll(), interrupt the poll(), and continue the iteration process.

context a T


:"~="(_ @ T, _ @ T)