419
434
<p class="since">Since 2.4
438
<div class="refsect2" lang="en">
439
<a name="id2851049"></a><h3>
440
<a name="gdk-threads-add-idle"></a>gdk_threads_add_idle ()</h3>
441
<a class="indexterm" name="id2851064"></a><pre class="programlisting">guint gdk_threads_add_idle (GSourceFunc function,
442
gpointer data);</pre>
444
A wrapper for the common usage of <a href="gdk-Threads.html#gdk-threads-add-idle-full"><code class="function">gdk_threads_add_idle_full()</code></a>
445
assigning the default priority, <span class="type">G_PRIORITY_DEFAULT_IDLE</span>.
448
See <a href="gdk-Threads.html#gdk-threads-add-idle-full"><code class="function">gdk_threads_add_idle_full()</code></a>.</p>
452
<div class="variablelist"><table border="0">
453
<col align="left" valign="top">
456
<td><span class="term"><em class="parameter"><code>function</code></em> :</span></td>
457
<td> function to call
461
<td><span class="term"><em class="parameter"><code>data</code></em> :</span></td>
462
<td> data to pass to <em class="parameter"><code>function</code></em>
466
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
467
<td> the ID (greater than 0) of the event source.
473
<p class="since">Since 2.12
477
<div class="refsect2" lang="en">
478
<a name="id2851197"></a><h3>
479
<a name="gdk-threads-add-idle-full"></a>gdk_threads_add_idle_full ()</h3>
480
<a class="indexterm" name="id2851213"></a><pre class="programlisting">guint gdk_threads_add_idle_full (gint priority,
481
GSourceFunc function,
483
GDestroyNotify notify);</pre>
485
Adds a function to be called whenever there are no higher priority
486
events pending. If the function returns <code class="literal">FALSE</code> it is automatically
487
removed from the list of event sources and will not be called again.
490
This variant of <code class="function">g_idle_add_full()</code> calls <em class="parameter"><code>function</code></em> with the GDK lock
491
held. It can be thought of a MT-safe version for GTK+ widgets for the
492
following use case, where you have to worry about <code class="function">idle_callback()</code>
493
running in thread A and accessing <em class="parameter"><code>self</code></em> after it has been finalized
498
<div class="informalexample"><pre class="programlisting">
499
static gboolean idle_callback (gpointer data)
501
SomeWidget *self = data;
503
/* do stuff with self */
505
self->idle_id = 0;
510
static void some_widget_do_stuff_later (SomeWidget *self)
512
self->idle_id = g_idle_add (idle_callback, self)
515
static void some_widget_finalize (GObject *object)
517
SomeWidget *self = SOME_WIDGET(object);
519
if (self->idle_id)
520
g_source_remove (self->idle_id);
522
G_OBJECT_CLASS (parent_class)->finalize (object);
528
<div class="variablelist"><table border="0">
529
<col align="left" valign="top">
532
<td><span class="term"><em class="parameter"><code>priority</code></em> :</span></td>
533
<td> the priority of the idle source. Typically this will be in the
534
range btweeen <span class="type">G_PRIORITY_DEFAULT_IDLE</span> and <span class="type">G_PRIORITY_HIGH_IDLE</span>
538
<td><span class="term"><em class="parameter"><code>function</code></em> :</span></td>
539
<td> function to call
543
<td><span class="term"><em class="parameter"><code>data</code></em> :</span></td>
544
<td> data to pass to <em class="parameter"><code>function</code></em>
548
<td><span class="term"><em class="parameter"><code>notify</code></em> :</span></td>
549
<td> function to call when the idle is removed, or <a
550
href="../liboil/liboil-liboiljunk.html#NULL:CAPS"
551
><code class="literal">NULL</code></a>
555
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
556
<td> the ID (greater than 0) of the event source.
562
<p class="since">Since 2.12
566
<div class="refsect2" lang="en">
567
<a name="id2851462"></a><h3>
568
<a name="gdk-threads-add-timeout"></a>gdk_threads_add_timeout ()</h3>
569
<a class="indexterm" name="id2851478"></a><pre class="programlisting">guint gdk_threads_add_timeout (guint interval,
570
GSourceFunc function,
571
gpointer data);</pre>
573
A wrapper for the common usage of <a href="gdk-Threads.html#gdk-threads-add-timeout-full"><code class="function">gdk_threads_add_timeout_full()</code></a>
574
assigning the default priority, <span class="type">G_PRIORITY_DEFAULT</span>.
577
See <a href="gdk-Threads.html#gdk-threads-add-timeout-full"><code class="function">gdk_threads_add_timeout_full()</code></a>.</p>
581
<div class="variablelist"><table border="0">
582
<col align="left" valign="top">
585
<td><span class="term"><em class="parameter"><code>interval</code></em> :</span></td>
586
<td> the time between calls to the function, in milliseconds
587
(1/1000ths of a second)
591
<td><span class="term"><em class="parameter"><code>function</code></em> :</span></td>
592
<td> function to call
596
<td><span class="term"><em class="parameter"><code>data</code></em> :</span></td>
597
<td> data to pass to <em class="parameter"><code>function</code></em>
601
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
602
<td> the ID (greater than 0) of the event source.
608
<p class="since">Since 2.12
612
<div class="refsect2" lang="en">
613
<a name="id2851633"></a><h3>
614
<a name="gdk-threads-add-timeout-full"></a>gdk_threads_add_timeout_full ()</h3>
615
<a class="indexterm" name="id2851649"></a><pre class="programlisting">guint gdk_threads_add_timeout_full (gint priority,
617
GSourceFunc function,
619
GDestroyNotify notify);</pre>
621
Sets a function to be called at regular intervals holding the GDK lock,
622
with the given priority. The function is called repeatedly until it
623
returns <code class="literal">FALSE</code>, at which point the timeout is automatically destroyed
624
and the function will not be called again. The <em class="parameter"><code>notify</code></em> function is
625
called when the timeout is destroyed. The first call to the
626
function will be at the end of the first <em class="parameter"><code>interval</code></em>.
629
Note that timeout functions may be delayed, due to the processing of other
630
event sources. Thus they should not be relied on for precise timing.
631
After each call to the timeout function, the time of the next
632
timeout is recalculated based on the current time and the given interval
633
(it does not try to 'catch up' time lost in delays).
636
This variant of <code class="function">g_timeout_add_full()</code> can be thought of a MT-safe version
637
for GTK+ widgets for the following use case:
641
<div class="informalexample"><pre class="programlisting">
642
static gboolean timeout_callback (gpointer data)
644
SomeWidget *self = data;
646
/* do stuff with self */
648
self->timeout_id = 0;
653
static void some_widget_do_stuff_later (SomeWidget *self)
655
self->timeout_id = g_timeout_add (timeout_callback, self)
658
static void some_widget_finalize (GObject *object)
660
SomeWidget *self = SOME_WIDGET(object);
662
if (self->timeout_id)
663
g_source_remove (self->timeout_id);
665
G_OBJECT_CLASS (parent_class)->finalize (object);
671
<div class="variablelist"><table border="0">
672
<col align="left" valign="top">
675
<td><span class="term"><em class="parameter"><code>priority</code></em> :</span></td>
676
<td> the priority of the timeout source. Typically this will be in the
677
range between <span class="type">G_PRIORITY_DEFAULT_IDLE</span> and <span class="type">G_PRIORITY_HIGH_IDLE</span>.
681
<td><span class="term"><em class="parameter"><code>interval</code></em> :</span></td>
682
<td> the time between calls to the function, in milliseconds
683
(1/1000ths of a second)
687
<td><span class="term"><em class="parameter"><code>function</code></em> :</span></td>
688
<td> function to call
692
<td><span class="term"><em class="parameter"><code>data</code></em> :</span></td>
693
<td> data to pass to <em class="parameter"><code>function</code></em>
697
<td><span class="term"><em class="parameter"><code>notify</code></em> :</span></td>
698
<td> function to call when the timeout is removed, or <a
699
href="../liboil/liboil-liboiljunk.html#NULL:CAPS"
700
><code class="literal">NULL</code></a>
704
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
705
<td> the ID (greater than 0) of the event source.
711
<p class="since">Since 2.12