MainContext

The GMainContext struct is an opaque data type representing a set of sources to be handled in a main loop.

Constructors

this
this(GMainContext* gMainContext, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this()

Creates a new #GMainContext structure.

Destructor

~this
~this()
Undocumented in source.

Members

Aliases

doref
alias doref = ref_
Undocumented in source.

Functions

acquire
bool acquire()

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 g_main_context_release() is called as many times as g_main_context_acquire().

addPoll
void addPoll(GPollFD* fd, int priority)

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 g_source_add_unix_fd() instead.

check
bool check(int maxPriority, GPollFD[] fds)

Passes the results of polling back to the main loop. You should be careful to pass @fds and its length @n_fds as received from g_main_context_query(), as this functions relies on assumptions on how @fds is filled.

dispatch
void dispatch()

Dispatches all pending sources.

findSourceByFuncsUserData
Source findSourceByFuncsUserData(GSourceFuncs* funcs, void* userData)

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.

findSourceById
Source findSourceById(uint sourceId)

Finds a #GSource given a pair of context and ID.

findSourceByUserData
Source findSourceByUserData(void* userData)

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.

getMainContextStruct
GMainContext* getMainContextStruct(bool transferOwnership)

Get the main Gtk struct

getPollFunc
GPollFunc getPollFunc()

Gets the poll function set by g_main_context_set_poll_func().

getStruct
void* getStruct()

the main Gtk struct as a void*

invoke
void invoke(GSourceFunc function_, void* data)

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

invokeFull
void invokeFull(int priority, GSourceFunc function_, void* data, GDestroyNotify notify)

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

isOwner
bool isOwner()

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

iteration
bool iteration(bool mayBlock)

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.

pending
bool pending()

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

popThreadDefault
void popThreadDefault()

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

prepare
bool prepare(int priority)

Prepares to poll sources within a main loop. The resulting information for polling is determined by calling g_main_context_query ().

pushThreadDefault
void pushThreadDefault()

Acquires @context and sets it as the thread-default context for the current thread. This will cause certain asynchronous operations (such as most giogio-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 g_main_context_get_thread_default(), not the one returned by g_main_context_default(), so it does not affect the context used by functions like g_idle_add().

query
int query(int maxPriority, int timeout, GPollFD[] fds)

Determines information necessary to poll this main loop. You should be careful to pass the resulting @fds array and its length @n_fds as is when calling g_main_context_check(), as this function relies on assumptions made when the array is filled.

ref_
MainContext ref_()

Increases the reference count on a #GMainContext object by one.

release
void release()

Releases ownership of a context previously acquired by this thread with g_main_context_acquire(). If the context was acquired multiple times, the ownership will be released only when g_main_context_release() is called as many times as it was acquired.

removePoll
void removePoll(GPollFD* fd)

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

setPollFunc
void setPollFunc(GPollFunc func)

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).

unref
void unref()

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

wait
bool wait(Cond cond, Mutex mutex)

Tries to become the owner of the specified context, as with g_main_context_acquire(). 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.

wakeup
void wakeup()

If @context is currently blocking in g_main_context_iteration() waiting for a source to become ready, cause it to stop blocking and return. Otherwise, cause the next invocation of g_main_context_iteration() to return without blocking.

Static functions

default_
MainContext default_()

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 g_main_context_get_thread_default().

getThreadDefault
MainContext getThreadDefault()

Gets the thread-default #GMainContext for this thread. Asynchronous operations that want to be able to be run in contexts other than the default one should call this method or g_main_context_ref_thread_default() to get a #GMainContext to add their #GSources 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 you are running in the default thread.)

refThreadDefault
MainContext refThreadDefault()

Gets the thread-default #GMainContext for this thread, as with g_main_context_get_thread_default(), but also adds a reference to it with g_main_context_ref(). In addition, unlike g_main_context_get_thread_default(), if the thread-default context is the global default context, this will return that #GMainContext (with a ref added to it) rather than returning %NULL.

Variables

gMainContext
GMainContext* gMainContext;

the main Gtk struct

ownedRef
bool ownedRef;
Undocumented in source.

Meta