📄 glib-asynchronous-queues.html
字号:
<a class="indexterm" name="id2911645"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a> g_async_queue_length (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue);</pre><p>Returns the length of the queue, negative values mean waitingthreads, positive values mean available entries in the<em class="parameter"><code>queue</code></em>. Actually this function returns the number of data items inthe queue minus the number of waiting threads. Thus a return valueof 0 could mean 'n' entries in the queue and 'n' thread waiting.That can happen due to locking of the queue or due toscheduling.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>queue</code></em> :</span></p></td><td> a <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a>.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the length of the <em class="parameter"><code>queue</code></em>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2911729"></a><h3><a name="g-async-queue-sort"></a>g_async_queue_sort ()</h3><a class="indexterm" name="id2911744"></a><pre class="programlisting">void g_async_queue_sort (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue, <a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>Sorts <em class="parameter"><code>queue</code></em> using <em class="parameter"><code>func</code></em>. </p><p>This function will lock <em class="parameter"><code>queue</code></em> before it sorts the queue and unlockit when it is finished.</p><p>If you were sorting a list of priority numbers to make sure thelowest priority would be at the top of the queue, you could use:</p><div class="informalexample"><pre class="programlisting"> gint32 id1; gint32 id2; id1 = GPOINTER_TO_INT (element1); id2 = GPOINTER_TO_INT (element2); return (id1 > id2 ? +1 : id1 == id2 ? 0 : -1);</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>queue</code></em> :</span></p></td><td> a <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td><td> the <a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc"><span class="type">GCompareDataFunc</span></a> is used to sort <em class="parameter"><code>queue</code></em>. This function is passed two elements of the <em class="parameter"><code>queue</code></em>. The function should return 0 if they are equal, a negative value if the first element should be higher in the <em class="parameter"><code>queue</code></em> or a positive value if the first element should be lower in the <em class="parameter"><code>queue</code></em> than the second element. </td></tr><tr><td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td><td> user data passed to <em class="parameter"><code>func</code></em></td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id2911932"></a><h3><a name="g-async-queue-lock"></a>g_async_queue_lock ()</h3><a class="indexterm" name="id2911945"></a><pre class="programlisting">void g_async_queue_lock (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue);</pre><p>Acquires the <em class="parameter"><code>queue</code></em>'s lock. After that you can only call the<code class="function">g_async_queue_*<code class="function">_unlocked()</code></code> function variants on that<em class="parameter"><code>queue</code></em>. Otherwise it will deadlock.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>queue</code></em> :</span></p></td><td> a <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2912029"></a><h3><a name="g-async-queue-unlock"></a>g_async_queue_unlock ()</h3><a class="indexterm" name="id2912043"></a><pre class="programlisting">void g_async_queue_unlock (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue);</pre><p>Releases the queue's lock.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>queue</code></em> :</span></p></td><td> a <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2912098"></a><h3><a name="g-async-queue-ref-unlocked"></a>g_async_queue_ref_unlocked ()</h3><a class="indexterm" name="id2912114"></a><pre class="programlisting">void g_async_queue_ref_unlocked (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue);</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p><code class="literal">g_async_queue_ref_unlocked</code> is deprecated and should not be used in newly-written code.</p></div><p>Increases the reference count of the asynchronous <em class="parameter"><code>queue</code></em> by 1.</p><p><em class="parameter"><code>Deprecated</code></em>: Since 2.8, reference counting is done atomicallyso <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-ref"><code class="function">g_async_queue_ref()</code></a> can be used regardless of the <em class="parameter"><code>queue</code></em>'slock.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>queue</code></em> :</span></p></td><td> a <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2912216"></a><h3><a name="g-async-queue-unref-and-unlock"></a>g_async_queue_unref_and_unlock ()</h3><a class="indexterm" name="id2912232"></a><pre class="programlisting">void g_async_queue_unref_and_unlock (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue);</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p><code class="literal">g_async_queue_unref_and_unlock</code> is deprecated and should not be used in newly-written code.</p></div><p>Decreases the reference count of the asynchronous <em class="parameter"><code>queue</code></em> by 1 andreleases the lock. This function must be called while holding the<em class="parameter"><code>queue</code></em>'s lock. If the reference count went to 0, the <em class="parameter"><code>queue</code></em> will bedestroyed and the memory allocated will be freed.</p><p><em class="parameter"><code>Deprecated</code></em>: Since 2.8, reference counting is done atomicallyso <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-unref"><code class="function">g_async_queue_unref()</code></a> can be used regardless of the <em class="parameter"><code>queue</code></em>'slock.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>queue</code></em> :</span></p></td><td> a <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2912348"></a><h3><a name="g-async-queue-push-unlocked"></a>g_async_queue_push_unlocked ()</h3><a class="indexterm" name="id2912362"></a><pre class="programlisting">void g_async_queue_push_unlocked (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data);</pre><p>Pushes the <em class="parameter"><code>data</code></em> into the <em class="parameter"><code>queue</code></em>. <em class="parameter"><code>data</code></em> must not be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. Thisfunction must be called while holding the <em class="parameter"><code>queue</code></em>'s lock.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>queue</code></em> :</span></p></td><td> a <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td><td> <em class="parameter"><code>data</code></em> to push into the <em class="parameter"><code>queue</code></em>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2912485"></a><h3><a name="g-async-queue-push-sorted-unlocked"></a>g_async_queue_push_sorted_unlocked ()</h3><a class="indexterm" name="id2912502"></a><pre class="programlisting">void g_async_queue_push_sorted_unlocked (<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue">GAsyncQueue</a> *queue, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data, <a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>Inserts <em class="parameter"><code>data</code></em> into <em class="parameter"><code>queue</code></em> using <em class="parameter"><code>func</code></em> to determine the newposition.</p><p>This function requires that the <em class="parameter"><code>queue</code></em> is sorted before pushing onnew elements.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -