895
895
boxes. Note that event sources are associated with a particular
896
896
<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
897
897
loops associated with that GMainContext.</p>
898
<p>GTK+ contains wrappers of some of these functions, e.g. <a href="http://developer.gnome.org/gtk2/gtk3-General.html#gtk-main"><code class="function">gtk_main()</code></a>,
899
<a href="http://developer.gnome.org/gtk2/gtk3-General.html#gtk-main-quit"><code class="function">gtk_main_quit()</code></a> and <a href="http://developer.gnome.org/gtk2/gtk3-General.html#gtk-events-pending"><code class="function">gtk_events_pending()</code></a>.</p>
898
<p>GTK+ contains wrappers of some of these functions, e.g. <code class="function">gtk_main()</code>,
899
<code class="function">gtk_main_quit()</code> and <code class="function">gtk_events_pending()</code>.</p>
900
900
<div class="refsect3">
901
901
<a name="id-1.4.2.6.9"></a><h4>Creating new source types</h4>
902
902
<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
1478
1478
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>,
1479
1479
<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>
1480
1480
<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>
1481
<p>It is a programmer error to attempt to lookup a non-existent source.</p>
1482
<p>More specifically: source IDs can be reissued after a source has been
1483
destroyed and therefore it is never valid to use this function with a
1484
source ID which may have already been removed. An example is when
1485
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
1486
idle may already have run and been removed by the time this function
1487
is called on its (now invalid) source ID. This source ID may have
1488
been reissued, leading to the operation being performed against the
1481
1490
<div class="refsect3">
1482
<a name="id-1.4.2.7.22.5"></a><h4>Parameters</h4>
1491
<a name="id-1.4.2.7.22.7"></a><h4>Parameters</h4>
1483
1492
<div class="informaltable"><table width="100%" border="0">
1485
1494
<col width="150px" class="parameters_name">
1617
<td class="listing_code"><pre class="programlisting"><span class="preproc">#define</span><span class="normal"> NUM_TASKS </span><span class="number">10</span>
1618
<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>
1619
<span class="symbol">...</span>
1620
<span class="normal"> </span>
1621
<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">(&</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>
1622
<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>
1626
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc ppc">#define NUM_TASKS 10</span>
1627
<span class="gtkdoc kwb">static</span> <span class="gtkdoc kwc">volatile</span> gint tasks_remaining <span class="gtkdoc opt">=</span> NUM_TASKS<span class="gtkdoc opt">;</span>
1628
<span class="gtkdoc opt">...</span>
1630
<span class="keyword">while</span> <span class="gtkdoc opt">(</span><span class="function"><a href="glib-Atomic-Operations.html#g-atomic-int-get">g_atomic_int_get</a></span> <span class="gtkdoc opt">(&</span>tasks_remaining<span class="gtkdoc opt">) !=</span> <span class="number">0</span><span class="gtkdoc opt">)</span>
1631
<span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-context-iteration">g_main_context_iteration</a></span> <span class="gtkdoc opt">(</span>NULL<span class="gtkdoc opt">,</span> TRUE<span class="gtkdoc opt">);</span></pre></td>
2208
<td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> </span><span class="usertype">GList</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">free_list</span><span class="symbol">;</span>
2210
<span class="normal"><a href="glib-Basic-Types.html#gpointer">gpointer</a></span>
2211
<span class="function">allocate_memory</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">gsize</span><span class="normal"> size</span><span class="symbol">)</span>
2212
<span class="cbracket">{</span><span class="normal"> </span>
2213
<span class="normal"> </span><span class="usertype">gpointer</span><span class="normal"> result </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Memory-Allocation.html#g-malloc">g_malloc</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">size</span><span class="symbol">);</span>
2214
<span class="normal"> free_list </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-prepend">g_list_prepend</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">free_list</span><span class="symbol">,</span><span class="normal"> result</span><span class="symbol">);</span>
2215
<span class="normal"> </span><span class="keyword">return</span><span class="normal"> result</span><span class="symbol">;</span>
2216
<span class="cbracket">}</span>
2218
<span class="type">void</span>
2219
<span class="function">free_allocated_memory</span><span class="normal"> </span><span class="symbol">(</span><span class="type">void</span><span class="symbol">)</span>
2220
<span class="cbracket">{</span>
2221
<span class="normal"> </span><span class="usertype">GList</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">l</span><span class="symbol">;</span>
2222
<span class="normal"> </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">l </span><span class="symbol">=</span><span class="normal"> free_list</span><span class="symbol">;</span><span class="normal"> l</span><span class="symbol">;</span><span class="normal"> l </span><span class="symbol">=</span><span class="normal"> l</span><span class="symbol">-></span><span class="normal">next</span><span class="symbol">);</span>
2223
<span class="normal"> </span><span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">l</span><span class="symbol">-></span><span class="normal">data</span><span class="symbol">);</span>
2224
<span class="normal"> </span><span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-free">g_list_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">free_list</span><span class="symbol">);</span>
2225
<span class="normal"> free_list </span><span class="symbol">=</span><span class="normal"> <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">;</span>
2226
<span class="normal"> </span><span class="cbracket">}</span>
2228
<span class="symbol">[...]</span>
2230
<span class="keyword">while</span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">);</span><span class="normal"> </span>
2231
<span class="normal"> </span><span class="cbracket">{</span>
2232
<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>
2233
<span class="normal"> </span><span class="function">free_allocated_memory</span><span class="symbol">();</span>
2234
<span class="normal"> </span><span class="cbracket">}</span></pre></td>
2217
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static</span> GList <span class="gtkdoc opt">*</span>free_list<span class="gtkdoc opt">;</span>
2220
<span class="function">allocate_memory</span> <span class="gtkdoc opt">(</span>gsize size<span class="gtkdoc opt">)</span>
2221
<span class="gtkdoc opt">{</span>
2222
gpointer result <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-Memory-Allocation.html#g-malloc">g_malloc</a></span> <span class="gtkdoc opt">(</span>size<span class="gtkdoc opt">);</span>
2223
free_list <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-prepend">g_list_prepend</a></span> <span class="gtkdoc opt">(</span>free_list<span class="gtkdoc opt">,</span> result<span class="gtkdoc opt">);</span>
2224
<span class="keyword">return</span> result<span class="gtkdoc opt">;</span>
2225
<span class="gtkdoc opt">}</span>
2227
<span class="gtkdoc kwb">void</span>
2228
<span class="function">free_allocated_memory</span> <span class="gtkdoc opt">(</span><span class="gtkdoc kwb">void</span><span class="gtkdoc opt">)</span>
2229
<span class="gtkdoc opt">{</span>
2230
GList <span class="gtkdoc opt">*</span>l<span class="gtkdoc opt">;</span>
2231
<span class="keyword">for</span> <span class="gtkdoc opt">(</span>l <span class="gtkdoc opt">=</span> free_list<span class="gtkdoc opt">;</span> l<span class="gtkdoc opt">;</span> l <span class="gtkdoc opt">=</span> l<span class="gtkdoc opt">-></span>next<span class="gtkdoc opt">);</span>
2232
<span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>l<span class="gtkdoc opt">-></span>data<span class="gtkdoc opt">);</span>
2233
<span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-free">g_list_free</a></span> <span class="gtkdoc opt">(</span>free_list<span class="gtkdoc opt">);</span>
2234
free_list <span class="gtkdoc opt">=</span> NULL<span class="gtkdoc opt">;</span>
2235
<span class="gtkdoc opt">}</span>
2237
<span class="gtkdoc opt">[...]</span>
2239
<span class="keyword">while</span> <span class="gtkdoc opt">(</span>TRUE<span class="gtkdoc opt">);</span>
2240
<span class="gtkdoc opt">{</span>
2241
<span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-context-iteration">g_main_context_iteration</a></span> <span class="gtkdoc opt">(</span>NULL<span class="gtkdoc opt">,</span> TRUE<span class="gtkdoc opt">);</span>
2242
<span class="function">free_allocated_memory</span><span class="gtkdoc opt">();</span>
2243
<span class="gtkdoc opt">}</span></pre></td>
2281
<td class="listing_code"><pre class="programlisting"><span class="normal"><a href="glib-Basic-Types.html#gpointer">gpointer</a></span>
2282
<span class="function">allocate_memory</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">gsize</span><span class="normal"> size</span><span class="symbol">)</span>
2283
<span class="cbracket">{</span><span class="normal"> </span>
2284
<span class="normal"> </span><span class="usertype">FreeListBlock</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">block </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Memory-Allocation.html#g-new">g_new</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">FreeListBlock</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1</span><span class="symbol">);</span>
2285
<span class="normal"> block</span><span class="symbol">-></span><span class="normal">mem </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Memory-Allocation.html#g-malloc">g_malloc</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">size</span><span class="symbol">);</span>
2286
<span class="normal"> block</span><span class="symbol">-></span><span class="normal">depth </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-depth">g_main_depth</a></span><span class="normal"> </span><span class="symbol">();</span><span class="normal"> </span>
2287
<span class="normal"> free_list </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-prepend">g_list_prepend</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">free_list</span><span class="symbol">,</span><span class="normal"> block</span><span class="symbol">);</span>
2288
<span class="normal"> </span><span class="keyword">return</span><span class="normal"> block</span><span class="symbol">-></span><span class="normal">mem</span><span class="symbol">;</span>
2289
<span class="cbracket">}</span>
2290
<td class="listing_code"><pre class="programlisting">gpointer
2291
<span class="function">allocate_memory</span> <span class="gtkdoc opt">(</span>gsize size<span class="gtkdoc opt">)</span>
2292
<span class="gtkdoc opt">{</span>
2293
FreeListBlock <span class="gtkdoc opt">*</span>block <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-Memory-Allocation.html#g-new">g_new</a></span> <span class="gtkdoc opt">(</span>FreeListBlock<span class="gtkdoc opt">,</span> <span class="number">1</span><span class="gtkdoc opt">);</span>
2294
block<span class="gtkdoc opt">-></span>mem <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-Memory-Allocation.html#g-malloc">g_malloc</a></span> <span class="gtkdoc opt">(</span>size<span class="gtkdoc opt">);</span>
2295
block<span class="gtkdoc opt">-></span>depth <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-depth">g_main_depth</a></span> <span class="gtkdoc opt">();</span>
2296
free_list <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-prepend">g_list_prepend</a></span> <span class="gtkdoc opt">(</span>free_list<span class="gtkdoc opt">,</span> block<span class="gtkdoc opt">);</span>
2297
<span class="keyword">return</span> block<span class="gtkdoc opt">-></span>mem<span class="gtkdoc opt">;</span>
2298
<span class="gtkdoc opt">}</span>
2291
<span class="type">void</span>
2292
<span class="function">free_allocated_memory</span><span class="normal"> </span><span class="symbol">(</span><span class="type">void</span><span class="symbol">)</span>
2293
<span class="cbracket">{</span>
2294
<span class="normal"> </span><span class="usertype">GList</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">l</span><span class="symbol">;</span>
2295
<span class="normal"> </span>
2296
<span class="normal"> </span><span class="type">int</span><span class="normal"> depth </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-depth">g_main_depth</a></span><span class="normal"> </span><span class="symbol">();</span>
2297
<span class="normal"> </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">l </span><span class="symbol">=</span><span class="normal"> free_list</span><span class="symbol">;</span><span class="normal"> l</span><span class="symbol">;</span><span class="normal"> </span><span class="symbol">);</span>
2298
<span class="normal"> </span><span class="cbracket">{</span>
2299
<span class="normal"> </span><span class="usertype">GList</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">next </span><span class="symbol">=</span><span class="normal"> l</span><span class="symbol">-></span><span class="normal">next</span><span class="symbol">;</span>
2300
<span class="normal"> </span><span class="usertype">FreeListBlock</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">block </span><span class="symbol">=</span><span class="normal"> l</span><span class="symbol">-></span><span class="normal">data</span><span class="symbol">;</span>
2301
<span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">block</span><span class="symbol">-></span><span class="normal">depth </span><span class="symbol">></span><span class="normal"> depth</span><span class="symbol">)</span>
2302
<span class="normal"> </span><span class="cbracket">{</span>
2303
<span class="normal"> </span><span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">block</span><span class="symbol">-></span><span class="normal">mem</span><span class="symbol">);</span>
2304
<span class="normal"> </span><span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">block</span><span class="symbol">);</span>
2305
<span class="normal"> free_list </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-delete-link">g_list_delete_link</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">free_list</span><span class="symbol">,</span><span class="normal"> l</span><span class="symbol">);</span>
2306
<span class="normal"> </span><span class="cbracket">}</span>
2307
<span class="normal"> </span>
2308
<span class="normal"> l </span><span class="symbol">=</span><span class="normal"> next</span><span class="symbol">;</span>
2309
<span class="normal"> </span><span class="cbracket">}</span>
2310
<span class="normal"> </span><span class="cbracket">}</span></pre></td>
2300
<span class="gtkdoc kwb">void</span>
2301
<span class="function">free_allocated_memory</span> <span class="gtkdoc opt">(</span><span class="gtkdoc kwb">void</span><span class="gtkdoc opt">)</span>
2302
<span class="gtkdoc opt">{</span>
2303
GList <span class="gtkdoc opt">*</span>l<span class="gtkdoc opt">;</span>
2305
<span class="gtkdoc kwb">int</span> depth <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-depth">g_main_depth</a></span> <span class="gtkdoc opt">();</span>
2306
<span class="keyword">for</span> <span class="gtkdoc opt">(</span>l <span class="gtkdoc opt">=</span> free_list<span class="gtkdoc opt">;</span> l<span class="gtkdoc opt">; );</span>
2307
<span class="gtkdoc opt">{</span>
2308
GList <span class="gtkdoc opt">*</span>next <span class="gtkdoc opt">=</span> l<span class="gtkdoc opt">-></span>next<span class="gtkdoc opt">;</span>
2309
FreeListBlock <span class="gtkdoc opt">*</span>block <span class="gtkdoc opt">=</span> l<span class="gtkdoc opt">-></span>data<span class="gtkdoc opt">;</span>
2310
<span class="keyword">if</span> <span class="gtkdoc opt">(</span>block<span class="gtkdoc opt">-></span>depth <span class="gtkdoc opt">></span> depth<span class="gtkdoc opt">)</span>
2311
<span class="gtkdoc opt">{</span>
2312
<span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>block<span class="gtkdoc opt">-></span>mem<span class="gtkdoc opt">);</span>
2313
<span class="function"><a href="glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>block<span class="gtkdoc opt">);</span>
2314
free_list <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-Doubly-Linked-Lists.html#g-list-delete-link">g_list_delete_link</a></span> <span class="gtkdoc opt">(</span>free_list<span class="gtkdoc opt">,</span> l<span class="gtkdoc opt">);</span>
2315
<span class="gtkdoc opt">}</span>
2317
l <span class="gtkdoc opt">=</span> next<span class="gtkdoc opt">;</span>
2318
<span class="gtkdoc opt">}</span>
2319
<span class="gtkdoc opt">}</span></pre></td>
3640
<td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> <a href="glib-Basic-Types.html#gboolean">gboolean</a> </span>
3641
<span class="function">idle_callback</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">gpointer</span><span class="normal"> data</span><span class="symbol">)</span>
3642
<span class="cbracket">{</span>
3643
<span class="normal"> </span><span class="usertype">SomeWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">self </span><span class="symbol">=</span><span class="normal"> data</span><span class="symbol">;</span>
3644
<span class="normal"> </span>
3645
<span class="normal"> </span><span class="function"><a href="http://developer.gnome.org/gdk2/gdk3-Threads.html#GDK-THREADS-ENTER:CAPS">GDK_THREADS_ENTER</a></span><span class="normal"> </span><span class="symbol">();</span>
3646
<span class="normal"> </span><span class="comment">// do stuff with self</span>
3647
<span class="normal"> self</span><span class="symbol">-></span><span class="normal">idle_id </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
3648
<span class="normal"> </span><span class="function"><a href="http://developer.gnome.org/gdk2/gdk3-Threads.html#GDK-THREADS-LEAVE:CAPS">GDK_THREADS_LEAVE</a></span><span class="normal"> </span><span class="symbol">();</span>
3649
<span class="normal"> </span>
3650
<span class="normal"> </span><span class="keyword">return</span><span class="normal"> <a href="glib-The-Main-Event-Loop.html#G-SOURCE-REMOVE:CAPS">G_SOURCE_REMOVE</a></span><span class="symbol">;</span>
3651
<span class="cbracket">}</span>
3652
<span class="normal"> </span>
3653
<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span>
3654
<span class="function">some_widget_do_stuff_later</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">SomeWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">self</span><span class="symbol">)</span>
3655
<span class="cbracket">{</span>
3656
<span class="normal"> self</span><span class="symbol">-></span><span class="normal">idle_id </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-idle-add">g_idle_add</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">idle_callback</span><span class="symbol">,</span><span class="normal"> self</span><span class="symbol">);</span>
3657
<span class="cbracket">}</span>
3658
<span class="normal"> </span>
3659
<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span>
3660
<span class="function">some_widget_finalize</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">object</span><span class="symbol">)</span>
3661
<span class="cbracket">{</span>
3662
<span class="normal"> </span><span class="usertype">SomeWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">self </span><span class="symbol">=</span><span class="normal"> </span><span class="function">SOME_WIDGET</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">object</span><span class="symbol">);</span>
3663
<span class="normal"> </span>
3664
<span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">self</span><span class="symbol">-></span><span class="normal">idle_id</span><span class="symbol">)</span>
3665
<span class="normal"> </span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-source-remove">g_source_remove</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">self</span><span class="symbol">-></span><span class="normal">idle_id</span><span class="symbol">);</span>
3666
<span class="normal"> </span>
3667
<span class="normal"> </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT-CLASS:CAPS">G_OBJECT_CLASS</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">parent_class</span><span class="symbol">)-></span><span class="function">finalize</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">object</span><span class="symbol">);</span>
3668
<span class="cbracket">}</span></pre></td>
3649
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static</span> gboolean
3650
<span class="function">idle_callback</span> <span class="gtkdoc opt">(</span>gpointer data<span class="gtkdoc opt">)</span>
3651
<span class="gtkdoc opt">{</span>
3652
SomeWidget <span class="gtkdoc opt">*</span>self <span class="gtkdoc opt">=</span> data<span class="gtkdoc opt">;</span>
3654
<span class="function">GDK_THREADS_ENTER</span> <span class="gtkdoc opt">();</span>
3655
<span class="gtkdoc slc">// do stuff with self</span>
3656
self<span class="gtkdoc opt">-></span>idle_id <span class="gtkdoc opt">=</span> <span class="number">0</span><span class="gtkdoc opt">;</span>
3657
<span class="function">GDK_THREADS_LEAVE</span> <span class="gtkdoc opt">();</span>
3659
<span class="keyword">return</span> G_SOURCE_REMOVE<span class="gtkdoc opt">;</span>
3660
<span class="gtkdoc opt">}</span>
3662
<span class="gtkdoc kwb">static void</span>
3663
<span class="function">some_widget_do_stuff_later</span> <span class="gtkdoc opt">(</span>SomeWidget <span class="gtkdoc opt">*</span>self<span class="gtkdoc opt">)</span>
3664
<span class="gtkdoc opt">{</span>
3665
self<span class="gtkdoc opt">-></span>idle_id <span class="gtkdoc opt">=</span> <span class="function"><a href="glib-The-Main-Event-Loop.html#g-idle-add">g_idle_add</a></span> <span class="gtkdoc opt">(</span>idle_callback<span class="gtkdoc opt">,</span> self<span class="gtkdoc opt">);</span>
3666
<span class="gtkdoc opt">}</span>
3668
<span class="gtkdoc kwb">static void</span>
3669
<span class="function">some_widget_finalize</span> <span class="gtkdoc opt">(</span>GObject <span class="gtkdoc opt">*</span>object<span class="gtkdoc opt">)</span>
3670
<span class="gtkdoc opt">{</span>
3671
SomeWidget <span class="gtkdoc opt">*</span>self <span class="gtkdoc opt">=</span> <span class="function">SOME_WIDGET</span> <span class="gtkdoc opt">(</span>object<span class="gtkdoc opt">);</span>
3673
<span class="keyword">if</span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">-></span>idle_id<span class="gtkdoc opt">)</span>
3674
<span class="function"><a href="glib-The-Main-Event-Loop.html#g-source-remove">g_source_remove</a></span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">-></span>idle_id<span class="gtkdoc opt">);</span>
3676
<span class="function"><a href="../gobject/gobject-The-Base-Object-Type.html#G-OBJECT-CLASS:CAPS">G_OBJECT_CLASS</a></span> <span class="gtkdoc opt">(</span>parent_class<span class="gtkdoc opt">)-></span><span class="function">finalize</span> <span class="gtkdoc opt">(</span>object<span class="gtkdoc opt">);</span>
3677
<span class="gtkdoc opt">}</span></pre></td>
3698
<td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> <a href="glib-Basic-Types.html#gboolean">gboolean</a> </span>
3699
<span class="function">idle_callback</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">gpointer</span><span class="normal"> data</span><span class="symbol">)</span>
3700
<span class="cbracket">{</span>
3701
<span class="normal"> </span><span class="usertype">SomeWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">self </span><span class="symbol">=</span><span class="normal"> data</span><span class="symbol">;</span>
3702
<span class="normal"> </span>
3703
<span class="normal"> </span><span class="function"><a href="http://developer.gnome.org/gdk2/gdk3-Threads.html#GDK-THREADS-ENTER:CAPS">GDK_THREADS_ENTER</a></span><span class="normal"> </span><span class="symbol">();</span>
3704
<span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(!</span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-source-is-destroyed">g_source_is_destroyed</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-current-source">g_main_current_source</a></span><span class="normal"> </span><span class="symbol">()))</span>
3705
<span class="normal"> </span><span class="cbracket">{</span>
3706
<span class="normal"> </span><span class="comment">// do stuff with self</span>
3707
<span class="normal"> </span><span class="cbracket">}</span>
3708
<span class="normal"> </span><span class="function"><a href="http://developer.gnome.org/gdk2/gdk3-Threads.html#GDK-THREADS-LEAVE:CAPS">GDK_THREADS_LEAVE</a></span><span class="normal"> </span><span class="symbol">();</span>
3709
<span class="normal"> </span>
3710
<span class="normal"> </span><span class="keyword">return</span><span class="normal"> <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">;</span>
3711
<span class="cbracket">}</span></pre></td>
3707
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static</span> gboolean
3708
<span class="function">idle_callback</span> <span class="gtkdoc opt">(</span>gpointer data<span class="gtkdoc opt">)</span>
3709
<span class="gtkdoc opt">{</span>
3710
SomeWidget <span class="gtkdoc opt">*</span>self <span class="gtkdoc opt">=</span> data<span class="gtkdoc opt">;</span>
3712
<span class="function">GDK_THREADS_ENTER</span> <span class="gtkdoc opt">();</span>
3713
<span class="keyword">if</span> <span class="gtkdoc opt">(!</span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-source-is-destroyed">g_source_is_destroyed</a></span> <span class="gtkdoc opt">(</span><span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-current-source">g_main_current_source</a></span> <span class="gtkdoc opt">()))</span>
3714
<span class="gtkdoc opt">{</span>
3715
<span class="gtkdoc slc">// do stuff with self</span>
3716
<span class="gtkdoc opt">}</span>
3717
<span class="function">GDK_THREADS_LEAVE</span> <span class="gtkdoc opt">();</span>
3719
<span class="keyword">return</span> FALSE<span class="gtkdoc opt">;</span>
3720
<span class="gtkdoc opt">}</span></pre></td>
3897
3906
<a name="g-source-get-name"></a><h3>g_source_get_name ()</h3>
3898
3907
<pre class="programlisting">const <span class="returnvalue">char</span> *
3899
3908
g_source_get_name (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>);</pre>
3900
<p>Gets a name for the source, used in debugging and profiling.
3901
The name may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><span class="type">NULL</span></a> if it has never been set with
3902
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-name" title="g_source_set_name ()"><code class="function">g_source_set_name()</code></a>.</p>
3909
<p>Gets a name for the source, used in debugging and profiling. The
3910
name may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><span class="type">NULL</span></a> if it has never been set with <a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-name" title="g_source_set_name ()"><code class="function">g_source_set_name()</code></a>.</p>
3903
3911
<div class="refsect3">
3904
3912
<a name="id-1.4.2.7.76.5"></a><h4>Parameters</h4>
3905
3913
<div class="informaltable"><table width="100%" border="0">
3935
3943
or "GTK+ repaint idle handler" or whatever it is.</p>
3936
3944
<p>It is permitted to call this function multiple times, but is not
3937
3945
recommended due to the potential performance impact. For example,
3938
one could change the name in the "check" function of a <a class="link" href="glib-The-Main-Event-Loop.html#GSourceFuncs" title="struct GSourceFuncs"><span class="type">GSourceFuncs</span></a>
3946
one could change the name in the "check" function of a <a class="link" href="glib-The-Main-Event-Loop.html#GSourceFuncs" title="struct GSourceFuncs"><span class="type">GSourceFuncs</span></a>
3939
3947
to include details like the event type in the source name.</p>
3948
<p>Use caution if changing the name while another thread may be
3949
accessing it with <a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-name" title="g_source_get_name ()"><code class="function">g_source_get_name()</code></a>; that function does not copy
3950
the value, and changing the value will free it while the other thread
3951
may be attempting to use it.</p>
3940
3952
<div class="refsect3">
3941
<a name="id-1.4.2.7.77.7"></a><h4>Parameters</h4>
3953
<a name="id-1.4.2.7.77.8"></a><h4>Parameters</h4>
3942
3954
<div class="informaltable"><table width="100%" border="0">
3944
3956
<col width="150px" class="parameters_name">
3970
3982
<p>Sets the name of a source using its ID.</p>
3971
3983
<p>This is a convenience utility to set source names from the return
3972
3984
value of <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>, <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>, etc.</p>
3985
<p>It is a programmer error to attempt to set the name of a non-existent
3987
<p>More specifically: source IDs can be reissued after a source has been
3988
destroyed and therefore it is never valid to use this function with a
3989
source ID which may have already been removed. An example is when
3990
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
3991
idle may already have run and been removed by the time this function
3992
is called on its (now invalid) source ID. This source ID may have
3993
been reissued, leading to the operation being performed against the
3973
3995
<div class="refsect3">
3974
<a name="id-1.4.2.7.78.6"></a><h4>Parameters</h4>
3996
<a name="id-1.4.2.7.78.8"></a><h4>Parameters</h4>
3975
3997
<div class="informaltable"><table width="100%" border="0">
3977
3999
<col width="150px" class="parameters_name">
4665
4687
<p>See also <a class="link" href="glib-The-Main-Event-Loop.html#g-source-destroy" title="g_source_destroy ()"><code class="function">g_source_destroy()</code></a>. You must use <a class="link" href="glib-The-Main-Event-Loop.html#g-source-destroy" title="g_source_destroy ()"><code class="function">g_source_destroy()</code></a> for sources
4666
4688
added to a non-default main context.</p>
4667
4689
<p>It is a programmer error to attempt to remove a non-existent source.</p>
4690
<p>More specifically: source IDs can be reissued after a source has been
4691
destroyed and therefore it is never valid to use this function with a
4692
source ID which may have already been removed. An example is when
4693
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
4694
idle may already have run and been removed by the time this function
4695
is called on its (now invalid) source ID. This source ID may have
4696
been reissued, leading to the operation being performed against the
4668
4698
<div class="refsect3">
4669
<a name="id-1.4.2.7.95.8"></a><h4>Parameters</h4>
4699
<a name="id-1.4.2.7.95.9"></a><h4>Parameters</h4>
4670
4700
<div class="informaltable"><table width="100%" border="0">
4672
4702
<col width="150px" class="parameters_name">