blob: a96463353ef5368263588d24df49424fcce52f56 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Asynchronous Queues</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-core.html" title="GLib Core Application Support">
<link rel="prev" href="glib-Thread-Pools.html" title="Thread Pools">
<link rel="next" href="glib-Dynamic-Loading-of-Modules.html" title="Dynamic Loading of Modules">
<meta name="generator" content="GTK-Doc V1.14 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Thread-Pools.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="glib-core.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GLib Reference Manual</th>
<td><a accesskey="n" href="glib-Dynamic-Loading-of-Modules.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#glib-Asynchronous-Queues.synopsis" class="shortcut">Top</a>
 | 
<a href="#glib-Asynchronous-Queues.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry" title="Asynchronous Queues">
<a name="glib-Asynchronous-Queues"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="glib-Asynchronous-Queues.top_of_page"></a>Asynchronous Queues</span></h2>
<p>Asynchronous Queues — asynchronous communication between threads</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv" title="Synopsis">
<a name="glib-Asynchronous-Queues.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include &lt;glib.h&gt;
<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue">GAsyncQueue</a>;
<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="returnvalue">GAsyncQueue</span></a>* <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-new" title="g_async_queue_new ()">g_async_queue_new</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="returnvalue">GAsyncQueue</span></a>* <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-new-full" title="g_async_queue_new_full ()">g_async_queue_new_full</a> (<em class="parameter"><code><a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> item_free_func</code></em>);
<a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="returnvalue">GAsyncQueue</span></a>* <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-ref" title="g_async_queue_ref ()">g_async_queue_ref</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-unref" title="g_async_queue_unref ()">g_async_queue_unref</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-push" title="g_async_queue_push ()">g_async_queue_push</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-push-sorted" title="g_async_queue_push_sorted ()">g_async_queue_push_sorted</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-pop" title="g_async_queue_pop ()">g_async_queue_pop</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-try-pop" title="g_async_queue_try_pop ()">g_async_queue_try_pop</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-timed-pop" title="g_async_queue_timed_pop ()">g_async_queue_timed_pop</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal" title="GTimeVal"><span class="type">GTimeVal</span></a> *end_time</code></em>);
<a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-length" title="g_async_queue_length ()">g_async_queue_length</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-sort" title="g_async_queue_sort ()">g_async_queue_sort</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-lock" title="g_async_queue_lock ()">g_async_queue_lock</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-unlock" title="g_async_queue_unlock ()">g_async_queue_unlock</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-ref-unlocked" title="g_async_queue_ref_unlocked ()">g_async_queue_ref_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-unref-and-unlock" title="g_async_queue_unref_and_unlock ()">g_async_queue_unref_and_unlock</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-push-unlocked" title="g_async_queue_push_unlocked ()">g_async_queue_push_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-push-sorted-unlocked" title="g_async_queue_push_sorted_unlocked ()">g_async_queue_push_sorted_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-pop-unlocked" title="g_async_queue_pop_unlocked ()">g_async_queue_pop_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-try-pop-unlocked" title="g_async_queue_try_pop_unlocked ()">g_async_queue_try_pop_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-timed-pop-unlocked" title="g_async_queue_timed_pop_unlocked ()">g_async_queue_timed_pop_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal" title="GTimeVal"><span class="type">GTimeVal</span></a> *end_time</code></em>);
<a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-length-unlocked" title="g_async_queue_length_unlocked ()">g_async_queue_length_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);
<span class="returnvalue">void</span> <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-sort-unlocked" title="g_async_queue_sort_unlocked ()">g_async_queue_sort_unlocked</a> (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
</pre>
</div>
<div class="refsect1" title="Description">
<a name="glib-Asynchronous-Queues.description"></a><h2>Description</h2>
<p>
Often you need to communicate between different threads. In general
it's safer not to do this by shared memory, but by explicit message
passing. These messages only make sense asynchronously for
multi-threaded applications though, as a synchronous operation could as
well be done in the same thread.
</p>
<p>
Asynchronous queues are an exception from most other GLib data
structures, as they can be used simultaneously from multiple threads
without explicit locking and they bring their own builtin reference
counting. This is because the nature of an asynchronous queue is that
it will always be used by at least 2 concurrent threads.
</p>
<p>
For using an asynchronous queue you first have to create one with
<a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-new" title="g_async_queue_new ()"><code class="function">g_async_queue_new()</code></a>. A newly-created queue will get the reference
count 1. Whenever another thread is creating a new reference of (that
is, pointer to) the queue, it has to increase the reference count
(using <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-ref" title="g_async_queue_ref ()"><code class="function">g_async_queue_ref()</code></a>). Also, before removing this reference, the
reference count has to be decreased (using
<a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-unref" title="g_async_queue_unref ()"><code class="function">g_async_queue_unref()</code></a>). After that the queue might no longer exist so
you must not access it after that point.
</p>
<p>
A thread, which wants to send a message to that queue simply calls
<a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-push" title="g_async_queue_push ()"><code class="function">g_async_queue_push()</code></a> to push the message to the queue.
</p>
<p>
A thread, which is expecting messages from an asynchronous queue
simply calls <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-pop" title="g_async_queue_pop ()"><code class="function">g_async_queue_pop()</code></a> for that queue. If no message is
available in the queue at that point, the thread is now put to sleep
until a message arrives. The message will be removed from the queue
and returned. The functions <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-try-pop" title="g_async_queue_try_pop ()"><code class="function">g_async_queue_try_pop()</code></a> and
<a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-timed-pop" title="g_async_queue_timed_pop ()"><code class="function">g_async_queue_timed_pop()</code></a> can be used to only check for the presence
of messages or to only wait a certain time for messages respectively.
</p>
<p>
For almost every function there exist two variants, one that locks the
queue and one that doesn't. That way you can hold the queue lock
(acquire it with <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-lock" title="g_async_queue_lock ()"><code class="function">g_async_queue_lock()</code></a> and release it with
<a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-unlock" title="g_async_queue_unlock ()"><code class="function">g_async_queue_unlock()</code></a>) over multiple queue accessing
instructions. This can be necessary to ensure the integrity of the
queue, but should only be used when really necessary, as it can make
your life harder if used unwisely. Normally you should only use the
locking function variants (those without the suffix _unlocked)
</p>
</div>
<div class="refsect1" title="Details">
<a name="glib-Asynchronous-Queues.details"></a><h2>Details</h2>
<div class="refsect2" title="GAsyncQueue">
<a name="GAsyncQueue"></a><h3>GAsyncQueue</h3>
<pre class="programlisting">typedef struct _GAsyncQueue GAsyncQueue;</pre>
<p>
The <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> struct is an opaque data structure, which represents
an asynchronous queue. It should only be accessed through the
<code class="function">g_async_queue_*</code> functions.
</p>
</div>
<hr>
<div class="refsect2" title="g_async_queue_new ()">
<a name="g-async-queue-new"></a><h3>g_async_queue_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="returnvalue">GAsyncQueue</span></a>* g_async_queue_new (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Creates a new asynchronous queue with the initial reference count of 1.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> the new <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_new_full ()">
<a name="g-async-queue-new-full"></a><h3>g_async_queue_new_full ()</h3>
<pre class="programlisting"><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="returnvalue">GAsyncQueue</span></a>* g_async_queue_new_full (<em class="parameter"><code><a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> item_free_func</code></em>);</pre>
<p>
Creates a new asynchronous queue with an initial reference count of 1 and
sets up a destroy notify function that is used to free any remaining
queue items when the queue is destroyed after the final unref.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>item_free_func</code></em> :</span></p></td>
<td>function to free queue elements
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> the new <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.16</p>
</div>
<hr>
<div class="refsect2" title="g_async_queue_ref ()">
<a name="g-async-queue-ref"></a><h3>g_async_queue_ref ()</h3>
<pre class="programlisting"><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="returnvalue">GAsyncQueue</span></a>* g_async_queue_ref (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Increases the reference count of the asynchronous <em class="parameter"><code>queue</code></em> by 1. You
do not need to hold the lock to call this function.
</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" title="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 <em class="parameter"><code>queue</code></em> that was passed in (since 2.6)
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_unref ()">
<a name="g-async-queue-unref"></a><h3>g_async_queue_unref ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_unref (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Decreases the reference count of the asynchronous <em class="parameter"><code>queue</code></em> by 1. If
the reference count went to 0, the <em class="parameter"><code>queue</code></em> will be destroyed and the
memory allocated will be freed. So you are not allowed to use the
<em class="parameter"><code>queue</code></em> afterwards, as it might have disappeared. You do not need to
hold the lock to call this function.
</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" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_push ()">
<a name="g-async-queue-push"></a><h3>g_async_queue_push ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_push (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>);</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" title="NULL"><code class="literal">NULL</code></a>.
</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" title="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" title="g_async_queue_push_sorted ()">
<a name="g-async-queue-push-sorted"></a><h3>g_async_queue_push_sorted ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_push_sorted (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</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 new
position.
</p>
<p>
This function requires that the <em class="parameter"><code>queue</code></em> is sorted before pushing on
new elements.
</p>
<p>
This function will lock <em class="parameter"><code>queue</code></em> before it sorts the queue and unlock
it when it is finished.
</p>
<p>
For an example of <em class="parameter"><code>func</code></em> see <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-sort" title="g_async_queue_sort ()"><code class="function">g_async_queue_sort()</code></a>.
</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" title="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>the <em class="parameter"><code>data</code></em> to push into the <em class="parameter"><code>queue</code></em>
</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" title="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" title="g_async_queue_pop ()">
<a name="g-async-queue-pop"></a><h3>g_async_queue_pop ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_async_queue_pop (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Pops data from the <em class="parameter"><code>queue</code></em>. This function blocks until data become
available.
</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" title="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> data from the queue.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_try_pop ()">
<a name="g-async-queue-try-pop"></a><h3>g_async_queue_try_pop ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_async_queue_try_pop (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Tries to pop data from the <em class="parameter"><code>queue</code></em>. If no data is available, <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is
returned.
</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" title="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> data from the queue or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, when no data is
available immediately.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_timed_pop ()">
<a name="g-async-queue-timed-pop"></a><h3>g_async_queue_timed_pop ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_async_queue_timed_pop (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal" title="GTimeVal"><span class="type">GTimeVal</span></a> *end_time</code></em>);</pre>
<p>
Pops data from the <em class="parameter"><code>queue</code></em>. If no data is received before <em class="parameter"><code>end_time</code></em>,
<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is returned.
</p>
<p>
To easily calculate <em class="parameter"><code>end_time</code></em> a combination of <a class="link" href="glib-Date-and-Time-Functions.html#g-get-current-time" title="g_get_current_time ()"><code class="function">g_get_current_time()</code></a>
and <a class="link" href="glib-Date-and-Time-Functions.html#g-time-val-add" title="g_time_val_add ()"><code class="function">g_time_val_add()</code></a> can be used.
</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" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>end_time</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal" title="GTimeVal"><span class="type">GTimeVal</span></a>, determining the final time.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> data from the queue or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, when no data is
received before <em class="parameter"><code>end_time</code></em>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_length ()">
<a name="g-async-queue-length"></a><h3>g_async_queue_length ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> g_async_queue_length (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Returns the length of the queue, negative values mean waiting
threads, positive values mean available entries in the
<em class="parameter"><code>queue</code></em>. Actually this function returns the number of data items in
the queue minus the number of waiting threads. Thus a return value
of 0 could mean 'n' entries in the queue and 'n' thread waiting.
That can happen due to locking of the queue or due to
scheduling.
</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" title="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" title="g_async_queue_sort ()">
<a name="g-async-queue-sort"></a><h3>g_async_queue_sort ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_sort (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</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 unlock
it when it is finished.
</p>
<p>
If you were sorting a list of priority numbers to make sure the
lowest priority would be at the top of the queue, you could use:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="normal"><a href="glib-Basic-Types.html#gint32">gint32</a> id1</span><span class="symbol">;</span>
<span class="normal"><a href="glib-Basic-Types.html#gint32">gint32</a> id2</span><span class="symbol">;</span>
<span class="normal"> </span>
<span class="normal">id1 </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Type-Conversion-Macros.html#GPOINTER-TO-INT:CAPS">GPOINTER_TO_INT</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">element1</span><span class="symbol">);</span>
<span class="normal">id2 </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Type-Conversion-Macros.html#GPOINTER-TO-INT:CAPS">GPOINTER_TO_INT</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">element2</span><span class="symbol">);</span>
<span class="normal"> </span>
<span class="keyword">return</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">id1 </span><span class="symbol">&gt;</span><span class="normal"> id2 </span><span class="symbol">?</span><span class="normal"> </span><span class="symbol">+</span><span class="number">1</span><span class="normal"> </span><span class="symbol">:</span><span class="normal"> id1 </span><span class="symbol">==</span><span class="normal"> id2 </span><span class="symbol">?</span><span class="normal"> </span><span class="number">0</span><span class="normal"> </span><span class="symbol">:</span><span class="normal"> </span><span class="symbol">-</span><span class="number">1</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</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" title="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" title="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" title="g_async_queue_lock ()">
<a name="g-async-queue-lock"></a><h3>g_async_queue_lock ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_lock (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</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_*_unlocked()</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" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_unlock ()">
<a name="g-async-queue-unlock"></a><h3>g_async_queue_unlock ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_unlock (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</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" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_ref_unlocked ()">
<a name="g-async-queue-ref-unlocked"></a><h3>g_async_queue_ref_unlocked ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_ref_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<div class="warning" title="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 atomically
so <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-ref" title="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>'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" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_unref_and_unlock ()">
<a name="g-async-queue-unref-and-unlock"></a><h3>g_async_queue_unref_and_unlock ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_unref_and_unlock (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<div class="warning" title="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 and
releases 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 be
destroyed and the memory allocated will be freed.
</p>
<p>
<em class="parameter"><code>Deprecated</code></em>: Since 2.8, reference counting is done atomically
so <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-unref" title="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>'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" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_push_unlocked ()">
<a name="g-async-queue-push-unlocked"></a><h3>g_async_queue_push_unlocked ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_push_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>);</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" title="NULL"><code class="literal">NULL</code></a>. This
function 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" title="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" title="g_async_queue_push_sorted_unlocked ()">
<a name="g-async-queue-push-sorted-unlocked"></a><h3>g_async_queue_push_sorted_unlocked ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_push_sorted_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</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 new
position.
</p>
<p>
This function requires that the <em class="parameter"><code>queue</code></em> is sorted before pushing on
new elements.
</p>
<p>
This function is called while holding the <em class="parameter"><code>queue</code></em>'s lock.
</p>
<p>
For an example of <em class="parameter"><code>func</code></em> see <a class="link" href="glib-Asynchronous-Queues.html#g-async-queue-sort" title="g_async_queue_sort ()"><code class="function">g_async_queue_sort()</code></a>.
</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" title="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>the <em class="parameter"><code>data</code></em> to push into the <em class="parameter"><code>queue</code></em>
</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" title="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" title="g_async_queue_pop_unlocked ()">
<a name="g-async-queue-pop-unlocked"></a><h3>g_async_queue_pop_unlocked ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_async_queue_pop_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Pops data from the <em class="parameter"><code>queue</code></em>. This function blocks until data become
available. This function 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" title="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> data from the queue.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_try_pop_unlocked ()">
<a name="g-async-queue-try-pop-unlocked"></a><h3>g_async_queue_try_pop_unlocked ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_async_queue_try_pop_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Tries to pop data from the <em class="parameter"><code>queue</code></em>. If no data is available, <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is
returned. This function 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" title="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> data from the queue or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, when no data is
available immediately.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_timed_pop_unlocked ()">
<a name="g-async-queue-timed-pop-unlocked"></a><h3>g_async_queue_timed_pop_unlocked ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_async_queue_timed_pop_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal" title="GTimeVal"><span class="type">GTimeVal</span></a> *end_time</code></em>);</pre>
<p>
Pops data from the <em class="parameter"><code>queue</code></em>. If no data is received before <em class="parameter"><code>end_time</code></em>,
<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is returned. This function must be called while holding the
<em class="parameter"><code>queue</code></em>'s lock.
</p>
<p>
To easily calculate <em class="parameter"><code>end_time</code></em> a combination of <a class="link" href="glib-Date-and-Time-Functions.html#g-get-current-time" title="g_get_current_time ()"><code class="function">g_get_current_time()</code></a>
and <a class="link" href="glib-Date-and-Time-Functions.html#g-time-val-add" title="g_time_val_add ()"><code class="function">g_time_val_add()</code></a> can be used.
</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" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>end_time</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal" title="GTimeVal"><span class="type">GTimeVal</span></a>, determining the final time.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td> data from the queue or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, when no data is
received before <em class="parameter"><code>end_time</code></em>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="g_async_queue_length_unlocked ()">
<a name="g-async-queue-length-unlocked"></a><h3>g_async_queue_length_unlocked ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> g_async_queue_length_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>);</pre>
<p>
Returns the length of the queue, negative values mean waiting
threads, positive values mean available entries in the
<em class="parameter"><code>queue</code></em>. Actually this function returns the number of data items in
the queue minus the number of waiting threads. Thus a return value
of 0 could mean 'n' entries in the queue and 'n' thread waiting.
That can happen due to locking of the queue or due to
scheduling. This function 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" title="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" title="g_async_queue_sort_unlocked ()">
<a name="g-async-queue-sort-unlocked"></a><h3>g_async_queue_sort_unlocked ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span> g_async_queue_sort_unlocked (<em class="parameter"><code><a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue" title="GAsyncQueue"><span class="type">GAsyncQueue</span></a> *queue</code></em>,
<em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> func</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>
Sorts <em class="parameter"><code>queue</code></em> using <em class="parameter"><code>func</code></em>.
</p>
<p>
This function is 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" title="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" title="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>
</div>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.14</div>
</body>
</html>