~ubuntu-branches/debian/jessie/glib2.0/jessie

« back to all changes in this revision

Viewing changes to docs/reference/glib/html/glib-The-Main-Event-Loop.html

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-09-23 10:12:15 UTC
  • mto: This revision was merged to the branch mainline in revision 120.
  • Revision ID: package-import@ubuntu.com-20140923101215-kg4894xy8gz996q1
Tags: upstream-2.42.0
Import upstream version 2.42.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
1489
wrong source.</p>
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">
1484
1493
<colgroup>
1485
1494
<col width="150px" class="parameters_name">
1501
1510
</table></div>
1502
1511
</div>
1503
1512
<div class="refsect3">
1504
 
<a name="id-1.4.2.7.22.6"></a><h4>Returns</h4>
1505
 
<p> the <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> if found, otherwise, <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. </p>
 
1513
<a name="id-1.4.2.7.22.8"></a><h4>Returns</h4>
 
1514
<p> the <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>. </p>
1506
1515
<p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p>
1507
1516
</div>
1508
1517
</div>
1614
1623
4
1615
1624
5
1616
1625
6</pre></td>
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">(&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>
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>
 
1629
 
 
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">(&amp;</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>
1623
1632
      </tr>
1624
1633
    </tbody>
1625
1634
  </table>
1635
1644
2
1636
1645
3
1637
1646
4</pre></td>
1638
 
        <td class="listing_code"><pre class="programlisting"><span class="function">perform_work</span><span class="symbol">();</span>
 
1647
        <td class="listing_code"><pre class="programlisting"><span class="function">perform_work</span><span class="gtkdoc opt">();</span>
1639
1648
 
1640
 
<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>
1641
 
<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>
 
1649
<span class="keyword">if</span> <span class="gtkdoc opt">(</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="gtkdoc opt">(&amp;</span>tasks_remaining<span class="gtkdoc opt">))</span>
 
1650
  <span class="function"><a href="glib-The-Main-Event-Loop.html#g-main-context-wakeup">g_main_context_wakeup</a></span> <span class="gtkdoc opt">(</span>NULL<span class="gtkdoc opt">);</span></pre></td>
1642
1651
      </tr>
1643
1652
    </tbody>
1644
1653
  </table>
2205
2214
25
2206
2215
26
2207
2216
27</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>
2209
 
 
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>
2217
 
 
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">-&gt;</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">-&gt;</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>
2227
 
 
2228
 
<span class="symbol">[...]</span>
2229
 
 
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>
 
2218
 
 
2219
gpointer
 
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>
 
2226
 
 
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">-&gt;</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">-&gt;</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>
 
2236
 
 
2237
<span class="gtkdoc opt">[...]</span>
 
2238
 
 
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>
2235
2244
      </tr>
2236
2245
    </tbody>
2237
2246
  </table>
2278
2287
28
2279
2288
29
2280
2289
30</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">-&gt;</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">-&gt;</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">-&gt;</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">-&gt;</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">-&gt;</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">-&gt;</span>mem<span class="gtkdoc opt">;</span>
 
2298
<span class="gtkdoc opt">}</span>
2290
2299
 
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">-&gt;</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">-&gt;</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">-&gt;</span><span class="normal">depth </span><span class="symbol">&gt;</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">-&gt;</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>
 
2304
  
 
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">-&gt;</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">-&gt;</span>data<span class="gtkdoc opt">;</span>
 
2310
      <span class="keyword">if</span> <span class="gtkdoc opt">(</span>block<span class="gtkdoc opt">-&gt;</span>depth <span class="gtkdoc opt">&gt;</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">-&gt;</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>
 
2316
              
 
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>
2311
2320
      </tr>
2312
2321
    </tbody>
2313
2322
  </table>
2326
2335
many things that the user could do. Instead, you can use the
2327
2336
following techniques:</p>
2328
2337
<div class="orderedlist"><ol class="orderedlist" type="1">
2329
 
<li class="listitem"><p>Use <a href="http://developer.gnome.org/gtk2/GtkWidget.html#gtk-widget-set-sensitive"><code class="function">gtk_widget_set_sensitive()</code></a> or modal dialogs to prevent
 
2338
<li class="listitem"><p>Use <code class="function">gtk_widget_set_sensitive()</code> or modal dialogs to prevent
2330
2339
the user from interacting with elements while the main
2331
2340
loop is recursing.</p></li>
2332
2341
<li class="listitem"><p>Avoid main loop recursion in situations where you can't handle
2579
2588
started while the non-default context is active.</p>
2580
2589
<p>Beware that libraries that predate this function may not correctly
2581
2590
handle being used from a thread with a thread-default context. Eg,
2582
 
see <a href="http://library.gnome.org/devel/gio/unstable/GFile.html#g-file-supports-thread-contexts"><code class="function">g_file_supports_thread_contexts()</code></a>.</p>
 
2591
see <a href="../gio/GFile.html#g-file-supports-thread-contexts"><code class="function">g_file_supports_thread_contexts()</code></a>.</p>
2583
2592
<div class="refsect3">
2584
2593
<a name="id-1.4.2.7.46.7"></a><h4>Parameters</h4>
2585
2594
<div class="informaltable"><table width="100%" border="0">
3402
3411
<a name="GSourceDummyMarshal"></a><h3>GSourceDummyMarshal ()</h3>
3403
3412
<pre class="programlisting"><span class="returnvalue">void</span>
3404
3413
<span class="c_punctuation">(</span>*GSourceDummyMarshal<span class="c_punctuation">)</span> (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
3405
 
<p>This is just a placeholder for <a href="http://library.gnome.org/devel/gobject/unstable/gobject-Closures.html#GClosureMarshal"><span class="type">GClosureMarshal</span></a>,
 
3414
<p>This is just a placeholder for <a href="../gobject/gobject-Closures.html#GClosureMarshal"><span class="type">GClosureMarshal</span></a>,
3406
3415
which cannot be used here for dependency reasons.</p>
3407
3416
</div>
3408
3417
<hr>
3637
3646
27
3638
3647
28
3639
3648
29</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">-&gt;</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">-&gt;</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">-&gt;</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">-&gt;</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">)-&gt;</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>
 
3653
   
 
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">-&gt;</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>
 
3658
   
 
3659
  <span class="keyword">return</span> G_SOURCE_REMOVE<span class="gtkdoc opt">;</span>
 
3660
<span class="gtkdoc opt">}</span>
 
3661
 
 
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">-&gt;</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>
 
3667
 
 
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>
 
3672
   
 
3673
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">-&gt;</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">-&gt;</span>idle_id<span class="gtkdoc opt">);</span>
 
3675
   
 
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">)-&gt;</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>
3669
3678
      </tr>
3670
3679
    </tbody>
3671
3680
  </table>
3695
3704
12
3696
3705
13
3697
3706
14</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>
 
3711
  
 
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>
 
3718
  
 
3719
  <span class="keyword">return</span> FALSE<span class="gtkdoc opt">;</span>
 
3720
<span class="gtkdoc opt">}</span></pre></td>
3712
3721
      </tr>
3713
3722
    </tbody>
3714
3723
  </table>
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">
3943
3955
<colgroup>
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
 
3986
source.</p>
 
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
 
3994
wrong source.</p>
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">
3976
3998
<colgroup>
3977
3999
<col width="150px" class="parameters_name">
4512
4534
its own prepare/check functions indicate that it is ready.)</p>
4513
4535
<p>If you don't need <em class="parameter"><code>child_source</code></em>
4514
4536
 to do anything on its own when it
4515
 
triggers, you can call <a href="http://library.gnome.org/devel/gobject/unstable/gobject-Closures.html#g-source-set-dummy-callback"><code class="function">g_source_set_dummy_callback()</code></a> on it to set a
 
4537
triggers, you can call <a href="../gobject/gobject-Closures.html#g-source-set-dummy-callback"><code class="function">g_source_set_dummy_callback()</code></a> on it to set a
4516
4538
callback that does nothing (except return <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if appropriate).</p>
4517
4539
<p><em class="parameter"><code>source</code></em>
4518
4540
 will hold a reference on <em class="parameter"><code>child_source</code></em>
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
 
4697
wrong source.</p>
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">
4671
4701
<colgroup>
4672
4702
<col width="150px" class="parameters_name">
4681
4711
</table></div>
4682
4712
</div>
4683
4713
<div class="refsect3">
4684
 
<a name="id-1.4.2.7.95.9"></a><h4>Returns</h4>
 
4714
<a name="id-1.4.2.7.95.10"></a><h4>Returns</h4>
4685
4715
<p> For historical reasons, this function always returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a></p>
4686
4716
<p></p>
4687
4717
</div>