Blame docs/reference/glib/html/glib-Asynchronous-Queues.html

Packit ae235b
Packit ae235b
<html>
Packit ae235b
<head>
Packit ae235b
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Packit ae235b
<title>Asynchronous Queues: GLib Reference Manual</title>
Packit ae235b
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
Packit ae235b
<link rel="home" href="index.html" title="GLib Reference Manual">
Packit ae235b
<link rel="up" href="glib-core.html" title="GLib Core Application Support">
Packit ae235b
<link rel="prev" href="glib-Thread-Pools.html" title="Thread Pools">
Packit ae235b
<link rel="next" href="glib-Dynamic-Loading-of-Modules.html" title="Dynamic Loading of Modules">
Packit ae235b
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
Packit ae235b
<link rel="stylesheet" href="style.css" type="text/css">
Packit ae235b
</head>
Packit ae235b
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Packit ae235b
Packit ae235b
Packit ae235b
Top  | 
Packit ae235b
                  Description
Packit ae235b
Packit ae235b
Home
Packit ae235b
Up
Packit ae235b
Prev
Packit ae235b
Next
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Asynchronous Queues

Packit ae235b

Asynchronous Queues — asynchronous communication between threads

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GAsyncQueue *
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_new ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GAsyncQueue *
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_new_full ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GAsyncQueue *
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_ref ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_unref ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_push ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_push_sorted ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_push_front ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_remove ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_pop ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_try_pop ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_timeout_pop ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gint
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_length ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_sort ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_lock ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_unlock ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_ref_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_unref_and_unlock ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_push_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_push_sorted_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_push_front_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_remove_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_pop_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_try_pop_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_timeout_pop_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gint
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_length_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
void
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_sort_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_timed_pop ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_async_queue_timed_pop_unlocked ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
 
Packit ae235b
GAsyncQueue
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Includes

Packit ae235b
#include <glib.h>
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Description

Packit ae235b

Often you need to communicate between different threads. In general

Packit ae235b
it's safer not to do this by shared memory, but by explicit message
Packit ae235b
passing. These messages only make sense asynchronously for
Packit ae235b
multi-threaded applications though, as a synchronous operation could
Packit ae235b
as well be done in the same thread.

Packit ae235b

Asynchronous queues are an exception from most other GLib data

Packit ae235b
structures, as they can be used simultaneously from multiple threads
Packit ae235b
without explicit locking and they bring their own builtin reference
Packit ae235b
counting. This is because the nature of an asynchronous queue is that
Packit ae235b
it will always be used by at least 2 concurrent threads.

Packit ae235b

For using an asynchronous queue you first have to create one with

Packit ae235b
g_async_queue_new(). GAsyncQueue structs are reference counted,
Packit ae235b
use g_async_queue_ref() and g_async_queue_unref() to manage your
Packit ae235b
references.

Packit ae235b

A thread which wants to send a message to that queue simply calls

Packit ae235b
g_async_queue_push() to push the message to the queue.

Packit ae235b

A thread which is expecting messages from an asynchronous queue

Packit ae235b
simply calls g_async_queue_pop() for that queue. If no message is
Packit ae235b
available in the queue at that point, the thread is now put to sleep
Packit ae235b
until a message arrives. The message will be removed from the queue
Packit ae235b
and returned. The functions g_async_queue_try_pop() and
Packit ae235b
g_async_queue_timeout_pop() can be used to only check for the presence
Packit ae235b
of messages or to only wait a certain time for messages respectively.

Packit ae235b

For almost every function there exist two variants, one that locks

Packit ae235b
the queue and one that doesn't. That way you can hold the queue lock
Packit ae235b
(acquire it with g_async_queue_lock() and release it with
Packit ae235b
g_async_queue_unlock()) over multiple queue accessing instructions.
Packit ae235b
This can be necessary to ensure the integrity of the queue, but should
Packit ae235b
only be used when really necessary, as it can make your life harder
Packit ae235b
if used unwisely. Normally you should only use the locking function
Packit ae235b
variants (those without the _unlocked suffix).

Packit ae235b

In many cases, it may be more convenient to use GThreadPool when

Packit ae235b
you need to distribute work to a set of worker threads instead of
Packit ae235b
using GAsyncQueue manually. GThreadPool uses a GAsyncQueue
Packit ae235b
internally.

Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b

g_async_queue_new ()

Packit ae235b
GAsyncQueue *
Packit ae235b
g_async_queue_new (void);
Packit ae235b

Creates a new asynchronous queue.

Packit ae235b
Packit ae235b

Returns

Packit ae235b

a new GAsyncQueue. Free with g_async_queue_unref()

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_new_full ()

Packit ae235b
GAsyncQueue *
Packit ae235b
g_async_queue_new_full (GDestroyNotify item_free_func);
Packit ae235b

Creates a new asynchronous queue and sets up a destroy notify

Packit ae235b
function that is used to free any remaining queue items when
Packit ae235b
the queue is destroyed after the final unref.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

item_free_func

Packit ae235b

function to free queue elements

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

a new GAsyncQueue. Free with g_async_queue_unref()

Packit ae235b
Packit ae235b

Since: 2.16

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_ref ()

Packit ae235b
GAsyncQueue *
Packit ae235b
g_async_queue_ref (GAsyncQueue *queue);
Packit ae235b

Increases the reference count of the asynchronous queue

Packit ae235b
 by 1.
Packit ae235b
You do not need to hold the lock to call this function.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the queue

Packit ae235b
that was passed in (since 2.6)

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_unref ()

Packit ae235b
void
Packit ae235b
g_async_queue_unref (GAsyncQueue *queue);
Packit ae235b

Decreases the reference count of the asynchronous queue

Packit ae235b
 by 1.

Packit ae235b

If the reference count went to 0, the queue

Packit ae235b
 will be destroyed
Packit ae235b
and the memory allocated will be freed. So you are not allowed
Packit ae235b
to use the queue
Packit ae235b
 afterwards, as it might have disappeared.
Packit ae235b
You do not need to hold the lock to call this function.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue.

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_push ()

Packit ae235b
void
Packit ae235b
g_async_queue_push (GAsyncQueue *queue,
Packit ae235b
                    gpointer data);
Packit ae235b

Pushes the data

Packit ae235b
 into the queue
Packit ae235b
. data
Packit ae235b
 must not be NULL.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

data

Packit ae235b
to push into the queue
Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_push_sorted ()

Packit ae235b
void
Packit ae235b
g_async_queue_push_sorted (GAsyncQueue *queue,
Packit ae235b
                           gpointer data,
Packit ae235b
                           GCompareDataFunc func,
Packit ae235b
                           gpointer user_data);
Packit ae235b

Inserts data

Packit ae235b
 into queue
Packit ae235b
 using func
Packit ae235b
 to determine the new
Packit ae235b
position.

Packit ae235b

This function requires that the queue

Packit ae235b
 is sorted before pushing on
Packit ae235b
new elements, see g_async_queue_sort().

Packit ae235b

This function will lock queue

Packit ae235b
 before it sorts the queue and unlock
Packit ae235b
it when it is finished.

Packit ae235b

For an example of func

Packit ae235b
 see g_async_queue_sort().

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

the data

Packit ae235b
to push into the queue
Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

func

Packit ae235b

the GCompareDataFunc is used to sort queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

user data passed to func

Packit ae235b
.

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.10

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_push_front ()

Packit ae235b
void
Packit ae235b
g_async_queue_push_front (GAsyncQueue *queue,
Packit ae235b
                          gpointer item);
Packit ae235b

Pushes the item

Packit ae235b
 into the queue
Packit ae235b
. item
Packit ae235b
 must not be NULL.
Packit ae235b
In contrast to g_async_queue_push(), this function
Packit ae235b
pushes the new item ahead of the items already in the queue,
Packit ae235b
so that it will be the next one to be popped off the queue.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

item

Packit ae235b

data to push into the queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.46

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_remove ()

Packit ae235b
gboolean
Packit ae235b
g_async_queue_remove (GAsyncQueue *queue,
Packit ae235b
                      gpointer item);
Packit ae235b

Remove an item from the queue.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

item

Packit ae235b

the data to remove from the queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE if the item was removed

Packit ae235b
Packit ae235b

Since: 2.46

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_pop ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_pop (GAsyncQueue *queue);
Packit ae235b

Pops data from the queue

Packit ae235b
. If queue
Packit ae235b
 is empty, this function
Packit ae235b
blocks until data becomes available.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_try_pop ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_try_pop (GAsyncQueue *queue);
Packit ae235b

Tries to pop data from the queue

Packit ae235b
. If no data is available,
Packit ae235b
NULL is returned.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue or NULL, when no data is

Packit ae235b
available immediately.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_timeout_pop ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_timeout_pop (GAsyncQueue *queue,
Packit ae235b
                           guint64 timeout);
Packit ae235b

Pops data from the queue

Packit ae235b
. If the queue is empty, blocks for
Packit ae235b
timeout
Packit ae235b
 microseconds, or until data becomes available.

Packit ae235b

If no data is received before the timeout, NULL is returned.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

timeout

Packit ae235b

the number of microseconds to wait

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue or NULL, when no data is

Packit ae235b
received before the timeout.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_length ()

Packit ae235b
gint
Packit ae235b
g_async_queue_length (GAsyncQueue *queue);
Packit ae235b

Returns the length of the queue.

Packit ae235b

Actually this function returns the number of data items in

Packit ae235b
the queue minus the number of waiting threads, so a negative
Packit ae235b
value means waiting threads, and a positive value means available
Packit ae235b
entries in the queue
Packit ae235b
. A return value of 0 could mean n entries
Packit ae235b
in the queue and n threads waiting. This can happen due to locking
Packit ae235b
of the queue or due to scheduling.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue.

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the length of the queue

Packit ae235b

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_sort ()

Packit ae235b
void
Packit ae235b
g_async_queue_sort (GAsyncQueue *queue,
Packit ae235b
                    GCompareDataFunc func,
Packit ae235b
                    gpointer user_data);
Packit ae235b

Sorts queue

Packit ae235b
 using func
Packit ae235b
.

Packit ae235b

The sort function func

Packit ae235b
 is passed two elements of the queue
Packit ae235b
.
Packit ae235b
It should return 0 if they are equal, a negative value if the
Packit ae235b
first element should be higher in the queue
Packit ae235b
 or a positive value
Packit ae235b
if the first element should be lower in the queue
Packit ae235b
 than the second
Packit ae235b
element.

Packit ae235b

This function will lock queue

Packit ae235b
 before it sorts the queue and unlock
Packit ae235b
it when it is finished.

Packit ae235b

If you were sorting a list of priority numbers to make sure the

Packit ae235b
lowest priority would be at the top of the queue, you could use:

Packit ae235b
Packit ae235b
  
Packit ae235b
    
Packit ae235b
      
Packit ae235b
        
1
Packit ae235b
2
Packit ae235b
3
Packit ae235b
4
Packit ae235b
5
Packit ae235b
6
Packit ae235b
7
Packit ae235b
        
gint32 id1;
Packit ae235b
gint32 id2;
Packit ae235b
Packit ae235b
id1 = GPOINTER_TO_INT (element1);
Packit ae235b
id2 = GPOINTER_TO_INT (element2);
Packit ae235b
Packit ae235b
return (id1 > id2 ? +1 : id1 == id2 ? 0 : -1);
Packit ae235b
      
Packit ae235b
    
Packit ae235b
  
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

func

Packit ae235b

the GCompareDataFunc is used to sort queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

user data passed to func

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.10

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_lock ()

Packit ae235b
void
Packit ae235b
g_async_queue_lock (GAsyncQueue *queue);
Packit ae235b

Acquires the queue

Packit ae235b
's lock. If another thread is already
Packit ae235b
holding the lock, this call will block until the lock
Packit ae235b
becomes available.

Packit ae235b

Call g_async_queue_unlock() to drop the lock again.

Packit ae235b

While holding the lock, you can only call the

Packit ae235b
g_async_queue_*_unlocked() functions on queue
Packit ae235b
. Otherwise,
Packit ae235b
deadlock may occur.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_unlock ()

Packit ae235b
void
Packit ae235b
g_async_queue_unlock (GAsyncQueue *queue);
Packit ae235b

Releases the queue's lock.

Packit ae235b

Calling this function when you have not acquired

Packit ae235b
the with g_async_queue_lock() leads to undefined
Packit ae235b
behaviour.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_ref_unlocked ()

Packit ae235b
void
Packit ae235b
g_async_queue_ref_unlocked (GAsyncQueue *queue);
Packit ae235b
Packit ae235b

g_async_queue_ref_unlocked has been deprecated since version 2.8 and should not be used in newly-written code.

Packit ae235b

Reference counting is done atomically.

Packit ae235b
so g_async_queue_ref() can be used regardless of the queue
Packit ae235b
's
Packit ae235b
lock.

Packit ae235b
Packit ae235b

Increases the reference count of the asynchronous queue

Packit ae235b
 by 1.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_unref_and_unlock ()

Packit ae235b
void
Packit ae235b
g_async_queue_unref_and_unlock (GAsyncQueue *queue);
Packit ae235b
Packit ae235b

g_async_queue_unref_and_unlock has been deprecated since version 2.8 and should not be used in newly-written code.

Packit ae235b

Reference counting is done atomically.

Packit ae235b
so g_async_queue_unref() can be used regardless of the queue
Packit ae235b
's
Packit ae235b
lock.

Packit ae235b
Packit ae235b

Decreases the reference count of the asynchronous queue

Packit ae235b
 by 1
Packit ae235b
and releases the lock. This function must be called while holding
Packit ae235b
the queue
Packit ae235b
's lock. If the reference count went to 0, the queue
Packit ae235b
Packit ae235b
will be destroyed and the memory allocated will be freed.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_push_unlocked ()

Packit ae235b
void
Packit ae235b
g_async_queue_push_unlocked (GAsyncQueue *queue,
Packit ae235b
                             gpointer data);
Packit ae235b

Pushes the data

Packit ae235b
 into the queue
Packit ae235b
. data
Packit ae235b
 must not be NULL.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

data

Packit ae235b
to push into the queue
Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_push_sorted_unlocked ()

Packit ae235b
void
Packit ae235b
g_async_queue_push_sorted_unlocked (GAsyncQueue *queue,
Packit ae235b
                                    gpointer data,
Packit ae235b
                                    GCompareDataFunc func,
Packit ae235b
                                    gpointer user_data);
Packit ae235b

Inserts data

Packit ae235b
 into queue
Packit ae235b
 using func
Packit ae235b
 to determine the new
Packit ae235b
position.

Packit ae235b

The sort function func

Packit ae235b
 is passed two elements of the queue
Packit ae235b
.
Packit ae235b
It should return 0 if they are equal, a negative value if the
Packit ae235b
first element should be higher in the queue
Packit ae235b
 or a positive value
Packit ae235b
if the first element should be lower in the queue
Packit ae235b
 than the second
Packit ae235b
element.

Packit ae235b

This function requires that the queue

Packit ae235b
 is sorted before pushing on
Packit ae235b
new elements, see g_async_queue_sort().

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b

For an example of func

Packit ae235b
 see g_async_queue_sort().

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

the data

Packit ae235b
to push into the queue
Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

func

Packit ae235b

the GCompareDataFunc is used to sort queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

user data passed to func

Packit ae235b
.

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.10

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_push_front_unlocked ()

Packit ae235b
void
Packit ae235b
g_async_queue_push_front_unlocked (GAsyncQueue *queue,
Packit ae235b
                                   gpointer item);
Packit ae235b

Pushes the item

Packit ae235b
 into the queue
Packit ae235b
. item
Packit ae235b
 must not be NULL.
Packit ae235b
In contrast to g_async_queue_push_unlocked(), this function
Packit ae235b
pushes the new item ahead of the items already in the queue,
Packit ae235b
so that it will be the next one to be popped off the queue.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

item

Packit ae235b

data to push into the queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.46

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_remove_unlocked ()

Packit ae235b
gboolean
Packit ae235b
g_async_queue_remove_unlocked (GAsyncQueue *queue,
Packit ae235b
                               gpointer item);
Packit ae235b

Remove an item from the queue.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

item

Packit ae235b

the data to remove from the queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

TRUE if the item was removed

Packit ae235b
Packit ae235b

Since: 2.46

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_pop_unlocked ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_pop_unlocked (GAsyncQueue *queue);
Packit ae235b

Pops data from the queue

Packit ae235b
. If queue
Packit ae235b
 is empty, this function
Packit ae235b
blocks until data becomes available.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_try_pop_unlocked ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_try_pop_unlocked (GAsyncQueue *queue);
Packit ae235b

Tries to pop data from the queue

Packit ae235b
. If no data is available,
Packit ae235b
NULL is returned.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue or NULL, when no data is

Packit ae235b
available immediately.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_timeout_pop_unlocked ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_timeout_pop_unlocked (GAsyncQueue *queue,
Packit ae235b
                                    guint64 timeout);
Packit ae235b

Pops data from the queue

Packit ae235b
. If the queue is empty, blocks for
Packit ae235b
timeout
Packit ae235b
 microseconds, or until data becomes available.

Packit ae235b

If no data is received before the timeout, NULL is returned.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

timeout

Packit ae235b

the number of microseconds to wait

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue or NULL, when no data is

Packit ae235b
received before the timeout.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_length_unlocked ()

Packit ae235b
gint
Packit ae235b
g_async_queue_length_unlocked (GAsyncQueue *queue);
Packit ae235b

Returns the length of the queue.

Packit ae235b

Actually this function returns the number of data items in

Packit ae235b
the queue minus the number of waiting threads, so a negative
Packit ae235b
value means waiting threads, and a positive value means available
Packit ae235b
entries in the queue
Packit ae235b
. A return value of 0 could mean n entries
Packit ae235b
in the queue and n threads waiting. This can happen due to locking
Packit ae235b
of the queue or due to scheduling.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the length of the queue

Packit ae235b
.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_sort_unlocked ()

Packit ae235b
void
Packit ae235b
g_async_queue_sort_unlocked (GAsyncQueue *queue,
Packit ae235b
                             GCompareDataFunc func,
Packit ae235b
                             gpointer user_data);
Packit ae235b

Sorts queue

Packit ae235b
 using func
Packit ae235b
.

Packit ae235b

The sort function func

Packit ae235b
 is passed two elements of the queue
Packit ae235b
.
Packit ae235b
It should return 0 if they are equal, a negative value if the
Packit ae235b
first element should be higher in the queue
Packit ae235b
 or a positive value
Packit ae235b
if the first element should be lower in the queue
Packit ae235b
 than the second
Packit ae235b
element.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

func

Packit ae235b

the GCompareDataFunc is used to sort queue

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

user_data

Packit ae235b

user data passed to func

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Since: 2.10

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_timed_pop ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_timed_pop (GAsyncQueue *queue,
Packit ae235b
                         GTimeVal *end_time);
Packit ae235b
Packit ae235b

g_async_queue_timed_pop is deprecated and should not be used in newly-written code.

Packit ae235b

use g_async_queue_timeout_pop().

Packit ae235b
Packit ae235b

Pops data from the queue

Packit ae235b
. If the queue is empty, blocks until
Packit ae235b
end_time
Packit ae235b
 or until data becomes available.

Packit ae235b

If no data is received before end_time

Packit ae235b
, NULL is returned.

Packit ae235b

To easily calculate end_time

Packit ae235b
, a combination of g_get_current_time()
Packit ae235b
and g_time_val_add() can be used.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

end_time

Packit ae235b

a GTimeVal, determining the final time

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue or NULL, when no data is

Packit ae235b
received before end_time
Packit ae235b
.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_async_queue_timed_pop_unlocked ()

Packit ae235b
gpointer
Packit ae235b
g_async_queue_timed_pop_unlocked (GAsyncQueue *queue,
Packit ae235b
                                  GTimeVal *end_time);
Packit ae235b
Packit ae235b

g_async_queue_timed_pop_unlocked is deprecated and should not be used in newly-written code.

Packit ae235b

use g_async_queue_timeout_pop_unlocked().

Packit ae235b
Packit ae235b

Pops data from the queue

Packit ae235b
. If the queue is empty, blocks until
Packit ae235b
end_time
Packit ae235b
 or until data becomes available.

Packit ae235b

If no data is received before end_time

Packit ae235b
, NULL is returned.

Packit ae235b

To easily calculate end_time

Packit ae235b
, a combination of g_get_current_time()
Packit ae235b
and g_time_val_add() can be used.

Packit ae235b

This function must be called while holding the queue

Packit ae235b
's lock.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

queue

Packit ae235b

a GAsyncQueue

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

end_time

Packit ae235b

a GTimeVal, determining the final time

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

data from the queue or NULL, when no data is

Packit ae235b
received before end_time
Packit ae235b
.

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b

GAsyncQueue

Packit ae235b
typedef struct _GAsyncQueue GAsyncQueue;
Packit ae235b

The GAsyncQueue struct is an opaque data structure which represents

Packit ae235b
an asynchronous queue. It should only be accessed through the
Packit ae235b
g_async_queue_* functions.

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

See Also

Packit ae235b

GThreadPool

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Generated by GTK-Doc V1.27
Packit ae235b
</body>
Packit ae235b
</html>