📄 gdk-threads.html
字号:
<p>Adds a function to be called whenever there are no higher priorityevents pending. If the function returns <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> it is automaticallyremoved from the list of event sources and will not be called again.</p><p>This variant of <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#g-idle-add-full"><code class="function">g_idle_add_full()</code></a> calls <em class="parameter"><code>function</code></em> with the GDK lockheld. It can be thought of a MT-safe version for GTK+ widgets for the following use case, where you have to worry about <code class="function">idle_callback()</code>running in thread A and accessing <em class="parameter"><code>self</code></em> after it has been finalizedin thread B:</p><p></p><div class="informalexample"><pre class="programlisting">static gbooleanidle_callback (gpointer data){ // gdk_threads_enter(); would be needed for g_idle_add() SomeWidget *self = data; /* do stuff with self */ self->idle_id = 0; // gdk_threads_leave(); would be needed for g_idle_add() return FALSE;}static voidsome_widget_do_stuff_later (SomeWidget *self){ self->idle_id = gdk_threads_add_idle (idle_callback, self) // using g_idle_add() here would require thread protection in the callback}static voidsome_widget_finalize (GObject *object){ SomeWidget *self = SOME_WIDGET (object); if (self->idle_id) g_source_remove (self->idle_id); G_OBJECT_CLASS (parent_class)->finalize (object);}</pre></div><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>priority</code></em> :</span></p></td><td> the priority of the idle source. Typically this will be in the range btweeen <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT-IDLE:CAPS"><span class="type">G_PRIORITY_DEFAULT_IDLE</span></a> and <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#G-PRIORITY-HIGH-IDLE:CAPS"><span class="type">G_PRIORITY_HIGH_IDLE</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>function</code></em> :</span></p></td><td> function to call</td></tr><tr><td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td><td> data to pass to <em class="parameter"><code>function</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>notify</code></em> :</span></p></td><td> function to call when the idle is removed, or <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the ID (greater than 0) of the event source.</td></tr></tbody></table></div><p class="since">Since 2.12</p></div><hr><div class="refsect2" lang="en"><a name="id3282244"></a><h3><a name="gdk-threads-add-timeout"></a>gdk_threads_add_timeout ()</h3><a class="indexterm" name="id3282260"></a><pre class="programlisting"><ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint">guint</a> gdk_threads_add_timeout (<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint">guint</a> interval, <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#GSourceFunc">GSourceFunc</a> function, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> data);</pre><p>A wrapper for the common usage of <a class="link" href="gdk-Threads.html#gdk-threads-add-timeout-full"><code class="function">gdk_threads_add_timeout_full()</code></a> assigning the default priority, <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT:CAPS"><span class="type">G_PRIORITY_DEFAULT</span></a>.</p><p>See <a class="link" href="gdk-Threads.html#gdk-threads-add-timeout-full"><code class="function">gdk_threads_add_timeout_full()</code></a>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>interval</code></em> :</span></p></td><td> the time between calls to the function, in milliseconds (1/1000ths of a second)</td></tr><tr><td><p><span class="term"><em class="parameter"><code>function</code></em> :</span></p></td><td> function to call</td></tr><tr><td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td><td> data to pass to <em class="parameter"><code>function</code></em></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the ID (greater than 0) of the event source.</td></tr></tbody></table></div><p class="since">Since 2.12</p></div><hr><div class="refsect2" lang="en"><a name="id3282415"></a><h3><a name="gdk-threads-add-timeout-full"></a>gdk_threads_add_timeout_full ()</h3><a class="indexterm" name="id3282431"></a><pre class="programlisting"><ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint">guint</a> gdk_threads_add_timeout_full (<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> priority, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint">guint</a> interval, <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#GSourceFunc">GSourceFunc</a> function, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> data, <ahref="/usr/share/gtk-doc/html/glib/glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> notify);</pre><p>Sets a function to be called at regular intervals holding the GDK lock,with the given priority. The function is called repeatedly until it returns <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>, at which point the timeout is automatically destroyed and the function will not be called again. The <em class="parameter"><code>notify</code></em> function iscalled when the timeout is destroyed. The first call to thefunction will be at the end of the first <em class="parameter"><code>interval</code></em>.</p><p>Note that timeout functions may be delayed, due to the processing of otherevent sources. Thus they should not be relied on for precise timing.After each call to the timeout function, the time of the nexttimeout is recalculated based on the current time and the given interval(it does not try to 'catch up' time lost in delays).</p><p>This variant of <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#g-timeout-add-full"><code class="function">g_timeout_add_full()</code></a> can be thought of a MT-safe version for GTK+ widgets for the following use case:</p><p></p><div class="informalexample"><pre class="programlisting">static gboolean timeout_callback (gpointer data){ SomeWidget *self = data; /* do stuff with self */ self->timeout_id = 0; return FALSE;} static void some_widget_do_stuff_later (SomeWidget *self){ self->timeout_id = g_timeout_add (timeout_callback, self)} static void some_widget_finalize (GObject *object){ SomeWidget *self = SOME_WIDGET(object); if (self->timeout_id) g_source_remove (self->timeout_id); G_OBJECT_CLASS (parent_class)->finalize (object);}</pre></div><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>priority</code></em> :</span></p></td><td> the priority of the timeout source. Typically this will be in the range between <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT-IDLE:CAPS"><span class="type">G_PRIORITY_DEFAULT_IDLE</span></a> and <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#G-PRIORITY-HIGH-IDLE:CAPS"><span class="type">G_PRIORITY_HIGH_IDLE</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>interval</code></em> :</span></p></td><td> the time between calls to the function, in milliseconds (1/1000ths of a second)</td></tr><tr><td><p><span class="term"><em class="parameter"><code>function</code></em> :</span></p></td><td> function to call</td></tr><tr><td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td><td> data to pass to <em class="parameter"><code>function</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>notify</code></em> :</span></p></td><td> function to call when the timeout is removed, or <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the ID (greater than 0) of the event source.</td></tr></tbody></table></div><p class="since">Since 2.12</p></div></div><div class="refsect1" lang="en"><a name="id3282702"></a><div class="refsect2" lang="en"><a name="id3282703"></a></div><hr><div class="refsect2" lang="en"><a name="id3282704"></a></div></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -