blob: 888d59edec200d415134606b8ed61be0356b7fc1 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>The Main Event Loop: GLib Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-core.html" title="GLib Core Application Support">
<link rel="prev" href="glib-core.html" title="GLib Core Application Support">
<link rel="next" href="glib-Threads.html" title="Threads">
<meta name="generator" content="GTK-Doc V1.25.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts">
<a href="#" class="shortcut">Top</a><span id="nav_description">  <span class="dim">|</span> 
<a href="#glib-The-Main-Event-Loop.description" class="shortcut">Description</a></span>
</td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="glib-core.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="glib-core.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="glib-Threads.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="glib-The-Main-Event-Loop"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="glib-The-Main-Event-Loop.top_of_page"></a>The Main Event Loop</span></h2>
<p>The Main Event Loop — manages all available sources of events</p>
</td>
<td class="gallery_image" valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="glib-The-Main-Event-Loop.functions"></a><h2>Functions</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="functions_return">
<col class="functions_name">
</colgroup>
<tbody>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="returnvalue">GMainLoop</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-new" title="g_main_loop_new ()">g_main_loop_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="returnvalue">GMainLoop</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-ref" title="g_main_loop_ref ()">g_main_loop_ref</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-unref" title="g_main_loop_unref ()">g_main_loop_unref</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-run" title="g_main_loop_run ()">g_main_loop_run</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-quit" title="g_main_loop_quit ()">g_main_loop_quit</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-is-running" title="g_main_loop_is_running ()">g_main_loop_is_running</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-get-context" title="g_main_loop_get_context ()">g_main_loop_get_context</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-new" title="g_main_new()">g_main_new</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-destroy" title="g_main_destroy()">g_main_destroy</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-run" title="g_main_run()">g_main_run</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-quit" title="g_main_quit()">g_main_quit</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-is-running" title="g_main_is_running()">g_main_is_running</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-new" title="g_main_context_new ()">g_main_context_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-ref" title="g_main_context_ref ()">g_main_context_ref</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-unref" title="g_main_context_unref ()">g_main_context_unref</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-default" title="g_main_context_default ()">g_main_context_default</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()">g_main_context_iteration</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-iteration" title="g_main_iteration()">g_main_iteration</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-pending" title="g_main_context_pending ()">g_main_context_pending</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#g-main-pending" title="g_main_pending">g_main_pending</a></td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-find-source-by-id" title="g_main_context_find_source_by_id ()">g_main_context_find_source_by_id</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-find-source-by-user-data" title="g_main_context_find_source_by_user_data ()">g_main_context_find_source_by_user_data</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-find-source-by-funcs-user-data" title="g_main_context_find_source_by_funcs_user_data ()">g_main_context_find_source_by_funcs_user_data</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-wakeup" title="g_main_context_wakeup ()">g_main_context_wakeup</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()">g_main_context_acquire</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-release" title="g_main_context_release ()">g_main_context_release</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-is-owner" title="g_main_context_is_owner ()">g_main_context_is_owner</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-wait" title="g_main_context_wait ()">g_main_context_wait</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-prepare" title="g_main_context_prepare ()">g_main_context_prepare</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-query" title="g_main_context_query ()">g_main_context_query</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-check" title="g_main_context_check ()">g_main_context_check</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-dispatch" title="g_main_context_dispatch ()">g_main_context_dispatch</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-set-poll-func" title="g_main_context_set_poll_func ()">g_main_context_set_poll_func</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GPollFunc" title="GPollFunc ()"><span class="returnvalue">GPollFunc</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-get-poll-func" title="g_main_context_get_poll_func ()">g_main_context_get_poll_func</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<span class="c_punctuation">(</span><a class="link" href="glib-The-Main-Event-Loop.html#GPollFunc" title="GPollFunc ()">*GPollFunc</a><span class="c_punctuation">)</span> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-add-poll" title="g_main_context_add_poll ()">g_main_context_add_poll</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-remove-poll" title="g_main_context_remove_poll ()">g_main_context_remove_poll</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-depth" title="g_main_depth ()">g_main_depth</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-current-source" title="g_main_current_source ()">g_main_current_source</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-set-poll-func" title="g_main_set_poll_func()">g_main_set_poll_func</a><span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-invoke" title="g_main_context_invoke ()">g_main_context_invoke</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-invoke-full" title="g_main_context_invoke_full ()">g_main_context_invoke_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-get-thread-default" title="g_main_context_get_thread_default ()">g_main_context_get_thread_default</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-ref-thread-default" title="g_main_context_ref_thread_default ()">g_main_context_ref_thread_default</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-push-thread-default" title="g_main_context_push_thread_default ()">g_main_context_push_thread_default</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-pop-thread-default" title="g_main_context_pop_thread_default ()">g_main_context_pop_thread_default</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-source-new" title="g_timeout_source_new ()">g_timeout_source_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-source-new-seconds" title="g_timeout_source_new_seconds ()">g_timeout_source_new_seconds</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add" title="g_timeout_add ()">g_timeout_add</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add-full" title="g_timeout_add_full ()">g_timeout_add_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add-seconds" title="g_timeout_add_seconds ()">g_timeout_add_seconds</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add-seconds-full" title="g_timeout_add_seconds_full ()">g_timeout_add_seconds_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-idle-source-new" title="g_idle_source_new ()">g_idle_source_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-idle-add" title="g_idle_add ()">g_idle_add</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-idle-add-full" title="g_idle_add_full ()">g_idle_add_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-idle-remove-by-data" title="g_idle_remove_by_data ()">g_idle_remove_by_data</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<span class="c_punctuation">(</span><a class="link" href="glib-The-Main-Event-Loop.html#GChildWatchFunc" title="GChildWatchFunc ()">*GChildWatchFunc</a><span class="c_punctuation">)</span> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-child-watch-source-new" title="g_child_watch_source_new ()">g_child_watch_source_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-child-watch-add" title="g_child_watch_add ()">g_child_watch_add</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-child-watch-add-full" title="g_child_watch_add_full ()">g_child_watch_add_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-poll" title="g_poll ()">g_poll</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<span class="c_punctuation">(</span><a class="link" href="glib-The-Main-Event-Loop.html#GSourceDummyMarshal" title="GSourceDummyMarshal ()">*GSourceDummyMarshal</a><span class="c_punctuation">)</span> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-new" title="g_source_new ()">g_source_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-ref" title="g_source_ref ()">g_source_ref</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-unref" title="g_source_unref ()">g_source_unref</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-funcs" title="g_source_set_funcs ()">g_source_set_funcs</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-attach" title="g_source_attach ()">g_source_attach</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-destroy" title="g_source_destroy ()">g_source_destroy</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-is-destroyed" title="g_source_is_destroyed ()">g_source_is_destroyed</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-priority" title="g_source_set_priority ()">g_source_set_priority</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-priority" title="g_source_get_priority ()">g_source_get_priority</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-can-recurse" title="g_source_set_can_recurse ()">g_source_set_can_recurse</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-can-recurse" title="g_source_get_can_recurse ()">g_source_get_can_recurse</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-id" title="g_source_get_id ()">g_source_get_id</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">const <span class="returnvalue">char</span> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-name" title="g_source_get_name ()">g_source_get_name</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-name" title="g_source_set_name ()">g_source_set_name</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-name-by-id" title="g_source_set_name_by_id ()">g_source_set_name_by_id</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-context" title="g_source_get_context ()">g_source_get_context</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-callback" title="g_source_set_callback ()">g_source_set_callback</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<span class="c_punctuation">(</span><a class="link" href="glib-The-Main-Event-Loop.html#GSourceFunc" title="GSourceFunc ()">*GSourceFunc</a><span class="c_punctuation">)</span> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-callback-indirect" title="g_source_set_callback_indirect ()">g_source_set_callback_indirect</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-ready-time" title="g_source_set_ready_time ()">g_source_set_ready_time</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint64" title="gint64"><span class="returnvalue">gint64</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-ready-time" title="g_source_get_ready_time ()">g_source_get_ready_time</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-unix-fd" title="g_source_add_unix_fd ()">g_source_add_unix_fd</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-unix-fd" title="g_source_remove_unix_fd ()">g_source_remove_unix_fd</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-modify-unix-fd" title="g_source_modify_unix_fd ()">g_source_modify_unix_fd</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="returnvalue">GIOCondition</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-query-unix-fd" title="g_source_query_unix_fd ()">g_source_query_unix_fd</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-poll" title="g_source_add_poll ()">g_source_add_poll</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-poll" title="g_source_remove_poll ()">g_source_remove_poll</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-child-source" title="g_source_add_child_source ()">g_source_add_child_source</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-child-source" title="g_source_remove_child_source ()">g_source_remove_child_source</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gint64" title="gint64"><span class="returnvalue">gint64</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-time" title="g_source_get_time ()">g_source_get_time</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-current-time" title="g_source_get_current_time ()">g_source_get_current_time</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove" title="g_source_remove ()">g_source_remove</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-by-funcs-user-data" title="g_source_remove_by_funcs_user_data ()">g_source_remove_by_funcs_user_data</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-by-user-data" title="g_source_remove_by_user_data ()">g_source_remove_by_user_data</a> <span class="c_punctuation">()</span>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="glib-The-Main-Event-Loop.other"></a><h2>Types and Values</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="name">
<col class="description">
</colgroup>
<tbody>
<tr>
<td class="datatype_keyword"> </td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop">GMainLoop</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-HIGH:CAPS" title="G_PRIORITY_HIGH">G_PRIORITY_HIGH</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT:CAPS" title="G_PRIORITY_DEFAULT">G_PRIORITY_DEFAULT</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-HIGH-IDLE:CAPS" title="G_PRIORITY_HIGH_IDLE">G_PRIORITY_HIGH_IDLE</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT-IDLE:CAPS" title="G_PRIORITY_DEFAULT_IDLE">G_PRIORITY_DEFAULT_IDLE</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-LOW:CAPS" title="G_PRIORITY_LOW">G_PRIORITY_LOW</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-SOURCE-CONTINUE:CAPS" title="G_SOURCE_CONTINUE">G_SOURCE_CONTINUE</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-SOURCE-REMOVE:CAPS" title="G_SOURCE_REMOVE">G_SOURCE_REMOVE</a></td>
</tr>
<tr>
<td class="datatype_keyword"> </td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext">GMainContext</a></td>
</tr>
<tr>
<td class="typedef_keyword">typedef</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#GPid" title="GPid">GPid</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-PID-FORMAT:CAPS" title="G_PID_FORMAT">G_PID_FORMAT</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#GPollFD" title="struct GPollFD">GPollFD</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#G-POLLFD-FORMAT:CAPS" title="G_POLLFD_FORMAT">G_POLLFD_FORMAT</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource">GSource</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#GSourceFuncs" title="struct GSourceFuncs">GSourceFuncs</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="glib-The-Main-Event-Loop.html#GSourceCallbackFuncs" title="struct GSourceCallbackFuncs">GSourceCallbackFuncs</a></td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="glib-The-Main-Event-Loop.includes"></a><h2>Includes</h2>
<pre class="synopsis">#include &lt;glib.h&gt;
</pre>
</div>
<div class="refsect1">
<a name="glib-The-Main-Event-Loop.description"></a><h2>Description</h2>
<p>The main event loop manages all the available sources of events for
GLib and GTK+ applications. These events can come from any number of
different types of sources such as file descriptors (plain files,
pipes or sockets) and timeouts. New types of event sources can also
be added using <a class="link" href="glib-The-Main-Event-Loop.html#g-source-attach" title="g_source_attach ()"><code class="function">g_source_attach()</code></a>.</p>
<p>To allow multiple independent sets of sources to be handled in
different threads, each source is associated with a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>.
A GMainContext can only be running in a single thread, but
sources can be added to it and removed from it from other threads.</p>
<p>Each event source is assigned a priority. The default priority,
<a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT:CAPS" title="G_PRIORITY_DEFAULT"><span class="type">G_PRIORITY_DEFAULT</span></a>, is 0. Values less than 0 denote higher priorities.
Values greater than 0 denote lower priorities. Events from high priority
sources are always processed before events from lower priority sources.</p>
<p>Idle functions can also be added, and assigned a priority. These will
be run whenever no events with a higher priority are ready to be processed.</p>
<p>The <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> data type represents a main event loop. A GMainLoop is
created with <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-new" title="g_main_loop_new ()"><code class="function">g_main_loop_new()</code></a>. After adding the initial event sources,
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-run" title="g_main_loop_run ()"><code class="function">g_main_loop_run()</code></a> is called. This continuously checks for new events from
each of the event sources and dispatches them. Finally, the processing of
an event from one of the sources leads to a call to <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-quit" title="g_main_loop_quit ()"><code class="function">g_main_loop_quit()</code></a> to
exit the main loop, and <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-run" title="g_main_loop_run ()"><code class="function">g_main_loop_run()</code></a> returns.</p>
<p>It is possible to create new instances of <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> recursively.
This is often used in GTK+ applications when showing modal dialog
boxes. Note that event sources are associated with a particular
<a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>, and will be checked and dispatched for all main
loops associated with that GMainContext.</p>
<p>GTK+ contains wrappers of some of these functions, e.g. <a href="http://developer.gnome.org/gtk3/gtk3-General.html#gtk-main"><code class="function">gtk_main()</code></a>,
<a href="http://developer.gnome.org/gtk3/gtk3-General.html#gtk-main-quit"><code class="function">gtk_main_quit()</code></a> and <a href="http://developer.gnome.org/gtk3/gtk3-General.html#gtk-events-pending"><code class="function">gtk_events_pending()</code></a>.</p>
<div class="refsect3">
<a name="id-1.4.2.6.9"></a><h4>Creating new source types</h4>
<p>One of the unusual features of the <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> functionality
is that new types of event source can be created and used in
addition to the builtin type of event source. A new event source
type is used for handling GDK events. A new source type is created
by "deriving" from the <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> structure. The derived type of
source is represented by a structure that has the <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> structure
as a first element, and other elements specific to the new source
type. To create an instance of the new source type, call
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-new" title="g_source_new ()"><code class="function">g_source_new()</code></a> passing in the size of the derived structure and
a table of functions. These <a class="link" href="glib-The-Main-Event-Loop.html#GSourceFuncs" title="struct GSourceFuncs"><span class="type">GSourceFuncs</span></a> determine the behavior of
the new source type.</p>
<p>New source types basically interact with the main context
in two ways. Their prepare function in <a class="link" href="glib-The-Main-Event-Loop.html#GSourceFuncs" title="struct GSourceFuncs"><span class="type">GSourceFuncs</span></a> can set a timeout
to determine the maximum amount of time that the main loop will sleep
before checking the source again. In addition, or as well, the source
can add file descriptors to the set that the main context checks using
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-poll" title="g_source_add_poll ()"><code class="function">g_source_add_poll()</code></a>.</p>
</div>
<div class="refsect3">
<a name="id-1.4.2.6.10"></a><h4>Customizing the main loop iteration</h4>
<p>Single iterations of a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> can be run with
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a>. In some cases, more detailed control
of exactly how the details of the main loop work is desired, for
instance, when integrating the <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> with an external main loop.
In such cases, you can call the component functions of
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a> directly. These functions are
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-prepare" title="g_main_context_prepare ()"><code class="function">g_main_context_prepare()</code></a>, <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-query" title="g_main_context_query ()"><code class="function">g_main_context_query()</code></a>,
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-check" title="g_main_context_check ()"><code class="function">g_main_context_check()</code></a> and <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-dispatch" title="g_main_context_dispatch ()"><code class="function">g_main_context_dispatch()</code></a>.</p>
</div>
<div class="refsect3">
<a name="mainloop-states"></a><h4>State of a Main Context</h4>
<p>The operation of these functions can best be seen in terms
of a state diagram, as shown in this image.</p>
<p><span class="inlinemediaobject"><img src="mainloop-states.gif"></span></p>
<p>On UNIX, the GLib mainloop is incompatible with <code class="function">fork()</code>. Any program
using the mainloop must either <code class="function">exec()</code> or <code class="function">exit()</code> from the child
without returning to the mainloop.</p>
</div>
<div class="refsect3">
<a name="mainloop-memory-management"></a><h4>Memory management of sources</h4>
<p>There are two options for memory management of the user data passed to a
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> to be passed to its callback on invocation. This data is provided
in calls to <a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add" title="g_timeout_add ()"><code class="function">g_timeout_add()</code></a>, <a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add-full" title="g_timeout_add_full ()"><code class="function">g_timeout_add_full()</code></a>, <a class="link" href="glib-The-Main-Event-Loop.html#g-idle-add" title="g_idle_add ()"><code class="function">g_idle_add()</code></a>, etc. and
more generally, using <a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-callback" title="g_source_set_callback ()"><code class="function">g_source_set_callback()</code></a>. This data is typically an
object which ‘owns’ the timeout or idle callback, such as a widget or a
network protocol implementation. In many cases, it is an error for the
callback to be invoked after this owning object has been destroyed, as that
results in use of freed memory.</p>
<p>The first, and preferred, option is to store the source ID returned by
functions such as <a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add" title="g_timeout_add ()"><code class="function">g_timeout_add()</code></a> or <a class="link" href="glib-The-Main-Event-Loop.html#g-source-attach" title="g_source_attach ()"><code class="function">g_source_attach()</code></a>, and explicitly
remove that source from the main context using <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove" title="g_source_remove ()"><code class="function">g_source_remove()</code></a> when the
owning object is finalized. This ensures that the callback can only be
invoked while the object is still alive.</p>
<p>The second option is to hold a strong reference to the object in the
callback, and to release it in the callback’s <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a>. This ensures
that the object is kept alive until after the source is finalized, which is
guaranteed to be after it is invoked for the final time. The <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a>
is another callback passed to the ‘full’ variants of <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> functions (for
example, <a class="link" href="glib-The-Main-Event-Loop.html#g-timeout-add-full" title="g_timeout_add_full ()"><code class="function">g_timeout_add_full()</code></a>). It is called when the source is finalized,
and is designed for releasing references like this.</p>
<p>One important caveat of this second approach is that it will keep the object
alive indefinitely if the main loop is stopped before the <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> is
invoked, which may be undesirable.</p>
</div>
</div>
<div class="refsect1">
<a name="glib-The-Main-Event-Loop.functions_details"></a><h2>Functions</h2>
<div class="refsect2">
<a name="g-main-loop-new"></a><h3>g_main_loop_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="returnvalue">GMainLoop</span></a> *
g_main_loop_new (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> is_running</code></em>);</pre>
<p>Creates a new <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> structure.</p>
<div class="refsect3">
<a name="g-main-loop-new.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p> a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> (if <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, the default context will be used). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>is_running</p></td>
<td class="parameter_description"><p>set to <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> to indicate that the loop is running. This
is not very important since calling <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-run" title="g_main_loop_run ()"><code class="function">g_main_loop_run()</code></a> will set this to
<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> anyway.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-loop-new.returns"></a><h4>Returns</h4>
<p> a new <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a>.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-loop-ref"></a><h3>g_main_loop_ref ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="returnvalue">GMainLoop</span></a> *
g_main_loop_ref (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> *loop</code></em>);</pre>
<p>Increases the reference count on a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> object by one.</p>
<div class="refsect3">
<a name="g-main-loop-ref.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-loop-ref.returns"></a><h4>Returns</h4>
<p> <em class="parameter"><code>loop</code></em>
</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-loop-unref"></a><h3>g_main_loop_unref ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_main_loop_unref (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> *loop</code></em>);</pre>
<p>Decreases the reference count on a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> object by one. If
the result is zero, free the loop and free all associated memory.</p>
<div class="refsect3">
<a name="g-main-loop-unref.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-loop-run"></a><h3>g_main_loop_run ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_main_loop_run (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> *loop</code></em>);</pre>
<p>Runs a main loop until <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-quit" title="g_main_loop_quit ()"><code class="function">g_main_loop_quit()</code></a> is called on the loop.
If this is called for the thread of the loop's <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>,
it will process events from the loop, otherwise it will
simply wait.</p>
<div class="refsect3">
<a name="g-main-loop-run.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-loop-quit"></a><h3>g_main_loop_quit ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_main_loop_quit (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> *loop</code></em>);</pre>
<p>Stops a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> from running. Any calls to <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-run" title="g_main_loop_run ()"><code class="function">g_main_loop_run()</code></a>
for the loop will return. </p>
<p>Note that sources that have already been dispatched when
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-quit" title="g_main_loop_quit ()"><code class="function">g_main_loop_quit()</code></a> is called will still be executed.</p>
<div class="refsect3">
<a name="g-main-loop-quit.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-loop-is-running"></a><h3>g_main_loop_is_running ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
g_main_loop_is_running (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> *loop</code></em>);</pre>
<p>Checks to see if the main loop is currently being run via <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-run" title="g_main_loop_run ()"><code class="function">g_main_loop_run()</code></a>.</p>
<div class="refsect3">
<a name="g-main-loop-is-running.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-loop-is-running.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the mainloop is currently being run.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-loop-get-context"></a><h3>g_main_loop_get_context ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
g_main_loop_get_context (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> *loop</code></em>);</pre>
<p>Returns the <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> of <em class="parameter"><code>loop</code></em>
.</p>
<div class="refsect3">
<a name="g-main-loop-get-context.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-loop-get-context.returns"></a><h4>Returns</h4>
<p> the <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> of <em class="parameter"><code>loop</code></em>
. </p>
<p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-new"></a><h3>g_main_new()</h3>
<pre class="programlisting">#define g_main_new(is_running)</pre>
<div class="warning">
<p><code class="literal">g_main_new</code> has been deprecated since version 2.2 and should not be used in newly-written code.</p>
<p>Use <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-new" title="g_main_loop_new ()"><code class="function">g_main_loop_new()</code></a> instead</p>
</div>
<p>Creates a new <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a> for th default main context.</p>
<div class="refsect3">
<a name="g-main-new.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>is_running</p></td>
<td class="parameter_description"><p>set to <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> to indicate that the loop is running. This
is not very important since calling <a class="link" href="glib-The-Main-Event-Loop.html#g-main-run" title="g_main_run()"><code class="function">g_main_run()</code></a> will set this
to <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> anyway.</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-new.returns"></a><h4>Returns</h4>
<p> a new <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-destroy"></a><h3>g_main_destroy()</h3>
<pre class="programlisting">#define g_main_destroy(loop)</pre>
<div class="warning">
<p><code class="literal">g_main_destroy</code> has been deprecated since version 2.2 and should not be used in newly-written code.</p>
<p>Use <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-unref" title="g_main_loop_unref ()"><code class="function">g_main_loop_unref()</code></a> instead</p>
</div>
<p>Frees the memory allocated for the <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a>.</p>
<div class="refsect3">
<a name="g-main-destroy.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-run"></a><h3>g_main_run()</h3>
<pre class="programlisting">#define g_main_run(loop)</pre>
<div class="warning">
<p><code class="literal">g_main_run</code> has been deprecated since version 2.2 and should not be used in newly-written code.</p>
<p>Use <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-run" title="g_main_loop_run ()"><code class="function">g_main_loop_run()</code></a> instead</p>
</div>
<p>Runs a main loop until it stops running.</p>
<div class="refsect3">
<a name="g-main-run.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-quit"></a><h3>g_main_quit()</h3>
<pre class="programlisting">#define g_main_quit(loop)</pre>
<div class="warning">
<p><code class="literal">g_main_quit</code> has been deprecated since version 2.2 and should not be used in newly-written code.</p>
<p>Use <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-quit" title="g_main_loop_quit ()"><code class="function">g_main_loop_quit()</code></a> instead</p>
</div>
<p>Stops the <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a>.
If <a class="link" href="glib-The-Main-Event-Loop.html#g-main-run" title="g_main_run()"><code class="function">g_main_run()</code></a> was called to run the <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a>, it will now return.</p>
<div class="refsect3">
<a name="g-main-quit.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-is-running"></a><h3>g_main_is_running()</h3>
<pre class="programlisting">#define g_main_is_running(loop)</pre>
<div class="warning">
<p><code class="literal">g_main_is_running</code> has been deprecated since version 2.2 and should not be used in newly-written code.</p>
<p>Use <a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-is-running" title="g_main_loop_is_running ()"><code class="function">g_main_loop_is_running()</code></a> instead</p>
</div>
<p>Checks if the main loop is running.</p>
<div class="refsect3">
<a name="g-main-is-running.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>loop</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-is-running.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the main loop is running</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-new"></a><h3>g_main_context_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
g_main_context_new (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>Creates a new <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> structure.</p>
<div class="refsect3">
<a name="g-main-context-new.returns"></a><h4>Returns</h4>
<p> the new <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-ref"></a><h3>g_main_context_ref ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
g_main_context_ref (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>Increases the reference count on a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> object by one.</p>
<div class="refsect3">
<a name="g-main-context-ref.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-ref.returns"></a><h4>Returns</h4>
<p> the <em class="parameter"><code>context</code></em>
that was passed in (since 2.6)</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-unref"></a><h3>g_main_context_unref ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_main_context_unref (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>Decreases the reference count on a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> object by one. If
the result is zero, free the context and free all associated memory.</p>
<div class="refsect3">
<a name="g-main-context-unref.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-default"></a><h3>g_main_context_default ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="returnvalue">GMainContext</span></a> *
g_main_context_default (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>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
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-get-thread-default" title="g_main_context_get_thread_default ()"><code class="function">g_main_context_get_thread_default()</code></a>.</p>
<div class="refsect3">
<a name="g-main-context-default.returns"></a><h4>Returns</h4>
<p> the global default main context. </p>
<p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-iteration"></a><h3>g_main_context_iteration ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
g_main_context_iteration (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> may_block</code></em>);</pre>
<p>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 <em class="parameter"><code>may_block</code></em>
is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>, waiting
for a source to become ready, then dispatching the highest priority
events sources that are ready. Otherwise, if <em class="parameter"><code>may_block</code></em>
is <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>
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.</p>
<p>Note that even when <em class="parameter"><code>may_block</code></em>
is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>, it is still possible for
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a> to return <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>, since the wait may
be interrupted for other reasons than an event source becoming ready.</p>
<div class="refsect3">
<a name="g-main-context-iteration.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p> a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> (if <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, the default context will be used). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>may_block</p></td>
<td class="parameter_description"><p>whether the call may block.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-iteration.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if events were dispatched.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-iteration"></a><h3>g_main_iteration()</h3>
<pre class="programlisting">#define g_main_iteration(may_block)</pre>
<div class="warning">
<p><code class="literal">g_main_iteration</code> has been deprecated since version 2.2 and should not be used in newly-written code.</p>
<p>Use <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a> instead.</p>
</div>
<p>Runs a single iteration for the default <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>.</p>
<div class="refsect3">
<a name="g-main-iteration.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>may_block</p></td>
<td class="parameter_description"><p>set to <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if it should block (i.e. wait) until an event
source becomes ready. It will return after an event source has been
processed. If set to <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> it will return immediately if no event
source is ready to be processed.</p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-iteration.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if more events are pending.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-pending"></a><h3>g_main_context_pending ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
g_main_context_pending (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>Checks if any sources have pending events for the given context.</p>
<div class="refsect3">
<a name="g-main-context-pending.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p> a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> (if <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, the default context will be used). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-pending.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if events are pending.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-pending"></a><h3>g_main_pending</h3>
<pre class="programlisting">#define g_main_pending()</pre>
<div class="warning"><p><code class="literal">g_main_pending</code> is deprecated and should not be used in newly-written code.</p></div>
<p>Checks if any events are pending for the default <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>
(i.e. ready to be processed).</p>
<div class="refsect3">
<a name="g-main-pending.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if any events are pending.</p>
<p>Deprected: 2.2: Use <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-pending" title="g_main_context_pending ()"><code class="function">g_main_context_pending()</code></a> instead.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-find-source-by-id"></a><h3>g_main_context_find_source_by_id ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
g_main_context_find_source_by_id (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint ()"><span class="type">guint</span></a> source_id</code></em>);</pre>
<p>Finds a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> given a pair of context and ID.</p>
<p>It is a programmer error to attempt to lookup a non-existent source.</p>
<p>More specifically: source IDs can be reissued after a source has been
destroyed and therefore it is never valid to use this function with a
source ID which may have already been removed. An example is when
scheduling an idle to run in another thread with <a class="link" href="glib-The-Main-Event-Loop.html#g-idle-add" title="g_idle_add ()"><code class="function">g_idle_add()</code></a>: the
idle may already have run and been removed by the time this function
is called on its (now invalid) source ID. This source ID may have
been reissued, leading to the operation being performed against the
wrong source.</p>
<div class="refsect3">
<a name="g-main-context-find-source-by-id.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p> a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> (if <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, the default context will be used). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>source_id</p></td>
<td class="parameter_description"><p>the source ID, as returned by <a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-id" title="g_source_get_id ()"><code class="function">g_source_get_id()</code></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-find-source-by-id.returns"></a><h4>Returns</h4>
<p> the <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>. </p>
<p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-find-source-by-user-data"></a><h3>g_main_context_find_source_by_user_data ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
g_main_context_find_source_by_user_data
(<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>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.</p>
<div class="refsect3">
<a name="g-main-context-find-source-by-user-data.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>user_data</p></td>
<td class="parameter_description"><p>the user_data for the callback.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-find-source-by-user-data.returns"></a><h4>Returns</h4>
<p> the source, if one was found, otherwise <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. </p>
<p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-find-source-by-funcs-user-data"></a><h3>g_main_context_find_source_by_funcs_user_data ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> *
g_main_context_find_source_by_funcs_user_data
(<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSourceFuncs" title="struct GSourceFuncs"><span class="type">GSourceFuncs</span></a> *funcs</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>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.</p>
<div class="refsect3">
<a name="g-main-context-find-source-by-funcs-user-data.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p> a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> (if <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, the default context will be used). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>funcs</p></td>
<td class="parameter_description"><p>the <em class="parameter"><code>source_funcs</code></em>
passed to <a class="link" href="glib-The-Main-Event-Loop.html#g-source-new" title="g_source_new ()"><code class="function">g_source_new()</code></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>user_data</p></td>
<td class="parameter_description"><p>the user data from the callback.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-find-source-by-funcs-user-data.returns"></a><h4>Returns</h4>
<p> the source, if one was found, otherwise <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. </p>
<p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-wakeup"></a><h3>g_main_context_wakeup ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_main_context_wakeup (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>If <em class="parameter"><code>context</code></em>
is currently blocking in <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a>
waiting for a source to become ready, cause it to stop blocking
and return. Otherwise, cause the next invocation of
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a> to return without blocking.</p>
<p>This API is useful for low-level control over <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>; for
example, integrating it with main loop implementations such as
<a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop" title="GMainLoop"><span class="type">GMainLoop</span></a>.</p>
<p>Another related use for this function is when implementing a main
loop with a termination condition, computed from multiple threads:</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="preproc">#define</span><span class="normal"> NUM_TASKS </span><span class="number">10</span>
<span class="keyword">static</span><span class="normal"> </span><span class="keyword">volatile</span><span class="normal"> </span><span class="usertype">gint</span><span class="normal"> tasks_remaining </span><span class="symbol">=</span><span class="normal"> NUM_TASKS</span><span class="symbol">;</span>
<span class="symbol">...</span>
<span class="normal"> </span>
<span class="keyword">while</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="glib-Atomic-Operations.html#g-atomic-int-get">g_atomic_int_get</a></span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">tasks_remaining</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">!=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal"> </span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-context-iteration">g_main_context_iteration</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p></p>
<p>Then in a thread:</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="function">perform_work</span><span class="symbol">();</span>
<span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="glib-Atomic-Operations.html#g-atomic-int-dec-and-test">g_atomic_int_dec_and_test</a></span><span class="normal"> </span><span class="symbol">(&amp;</span><span class="normal">tasks_remaining</span><span class="symbol">))</span>
<span class="normal"> </span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-context-wakeup">g_main_context_wakeup</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p></p>
<div class="refsect3">
<a name="g-main-context-wakeup.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-acquire"></a><h3>g_main_context_acquire ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
g_main_context_acquire (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>Tries to become the owner of the specified context.
If some other thread is the owner of the context,
returns <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> immediately. Ownership is properly
recursive: the owner can require ownership again
and will release ownership when <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-release" title="g_main_context_release ()"><code class="function">g_main_context_release()</code></a>
is called as many times as <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()"><code class="function">g_main_context_acquire()</code></a>.</p>
<p>You must be the owner of a context before you
can call <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-prepare" title="g_main_context_prepare ()"><code class="function">g_main_context_prepare()</code></a>, <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-query" title="g_main_context_query ()"><code class="function">g_main_context_query()</code></a>,
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-check" title="g_main_context_check ()"><code class="function">g_main_context_check()</code></a>, <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-dispatch" title="g_main_context_dispatch ()"><code class="function">g_main_context_dispatch()</code></a>.</p>
<div class="refsect3">
<a name="g-main-context-acquire.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-acquire.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the operation succeeded, and
this thread is now the owner of <em class="parameter"><code>context</code></em>
.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-release"></a><h3>g_main_context_release ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_main_context_release (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>Releases ownership of a context previously acquired by this thread
with <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()"><code class="function">g_main_context_acquire()</code></a>. If the context was acquired multiple
times, the ownership will be released only when <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-release" title="g_main_context_release ()"><code class="function">g_main_context_release()</code></a>
is called as many times as it was acquired.</p>
<div class="refsect3">
<a name="g-main-context-release.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-is-owner"></a><h3>g_main_context_is_owner ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
g_main_context_is_owner (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>Determines whether this thread holds the (recursive)
ownership of this <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>. This is useful to
know before waiting on another thread that may be
blocking to get ownership of <em class="parameter"><code>context</code></em>
.</p>
<div class="refsect3">
<a name="g-main-context-is-owner.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody><tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr></tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-is-owner.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if current thread is owner of <em class="parameter"><code>context</code></em>
.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-10.html#api-index-2.10">2.10</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-wait"></a><h3>g_main_context_wait ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
g_main_context_wait (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Threads.html#GCond" title="struct GCond"><span class="type">GCond</span></a> *cond</code></em>,
<em class="parameter"><code><a class="link" href="glib-Threads.html#GMutex" title="union GMutex"><span class="type">GMutex</span></a> *mutex</code></em>);</pre>
<p>Tries to become the owner of the specified context,
as with <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()"><code class="function">g_main_context_acquire()</code></a>. But if another thread
is the owner, atomically drop <em class="parameter"><code>mutex</code></em>
and wait on <em class="parameter"><code>cond</code></em>
until
that owner releases ownership or until <em class="parameter"><code>cond</code></em>
is signaled, then
try again (once) to become the owner.</p>
<div class="refsect3">
<a name="g-main-context-wait.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cond</p></td>
<td class="parameter_description"><p>a condition variable</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>mutex</p></td>
<td class="parameter_description"><p>a mutex, currently held</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-wait.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the operation succeeded, and
this thread is now the owner of <em class="parameter"><code>context</code></em>
.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-prepare"></a><h3>g_main_context_prepare ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a>
g_main_context_prepare (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="type">gint</span></a> *priority</code></em>);</pre>
<p>Prepares to poll sources within a main loop. The resulting information
for polling is determined by calling <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-query" title="g_main_context_query ()"><code class="function">g_main_context_query()</code></a>.</p>
<p>You must have successfully acquired the context with
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()"><code class="function">g_main_context_acquire()</code></a> before you may call this function.</p>
<div class="refsect3">
<a name="g-main-context-prepare.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>priority</p></td>
<td class="parameter_description"><p>location to store priority of highest priority
source already ready.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-prepare.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if some source is ready to be dispatched
prior to polling.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-query"></a><h3>g_main_context_query ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
g_main_context_query (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="type">gint</span></a> max_priority</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="type">gint</span></a> *timeout_</code></em>,
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GPollFD" title="struct GPollFD"><span class="type">GPollFD</span></a> *fds</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="type">gint</span></a> n_fds</code></em>);</pre>
<p>Determines information necessary to poll this main loop.</p>
<p>You must have successfully acquired the context with
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()"><code class="function">g_main_context_acquire()</code></a> before you may call this function.</p>
<div class="refsect3">
<a name="g-main-context-query.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>max_priority</p></td>
<td class="parameter_description"><p>maximum priority source to check</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>timeout_</p></td>
<td class="parameter_description"><p> location to store timeout to be used in polling. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>fds</p></td>
<td class="parameter_description"><p> location to
store <a class="link" href="glib-The-Main-Event-Loop.html#GPollFD" title="struct GPollFD"><span class="type">GPollFD</span></a> records that need to be polled. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Out parameter, where caller must allocate storage."><span class="acronym">out caller-allocates</span></acronym>][<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=n_fds]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>n_fds</p></td>
<td class="parameter_description"><p> length of <em class="parameter"><code>fds</code></em>
. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for input. Default is transfer none."><span class="acronym">in</span></acronym>]</span></td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-query.returns"></a><h4>Returns</h4>
<p> the number of records actually stored in <em class="parameter"><code>fds</code></em>
,
or, if more than <em class="parameter"><code>n_fds</code></em>
records need to be stored, the number
of records that need to be stored.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-check"></a><h3>g_main_context_check ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="returnvalue">gint</span></a>
g_main_context_check (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="type">gint</span></a> max_priority</code></em>,
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GPollFD" title="struct GPollFD"><span class="type">GPollFD</span></a> *fds</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint ()"><span class="type">gint</span></a> n_fds</code></em>);</pre>
<p>Passes the results of polling back to the main loop.</p>
<p>You must have successfully acquired the context with
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()"><code class="function">g_main_context_acquire()</code></a> before you may call this function.</p>
<div class="refsect3">
<a name="g-main-context-check.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>context</p></td>
<td class="parameter_description"><p>a <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>max_priority</p></td>
<td class="parameter_description"><p>the maximum numerical priority of sources to check</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>fds</p></td>
<td class="parameter_description"><p> array of <a class="link" href="glib-The-Main-Event-Loop.html#GPollFD" title="struct GPollFD"><span class="type">GPollFD</span></a>'s that was passed to
the last call to <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-query" title="g_main_context_query ()"><code class="function">g_main_context_query()</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=n_fds]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>n_fds</p></td>
<td class="parameter_description"><p>return value of <a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-query" title="g_main_context_query ()"><code class="function">g_main_context_query()</code></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-main-context-check.returns"></a><h4>Returns</h4>
<p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if some sources are ready to be dispatched.</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="g-main-context-dispatch"></a><h3>g_main_context_dispatch ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
g_main_context_dispatch (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a> *context</code></em>);</pre>
<p>Dispatches all pending sources.</p>
<p>You must have successfully acquired the context with
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-acquire" title="g_main_context_acquire ()"><code class="function">g_main_context_acquire()</code></a> before you may call this function.</p>
<div class="refsect3">
<a name="g-main-context-dispatch.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>