gasyncqueue.h File Reference

__G_ASYNCQUEUE_H__

Typedef GAsyncQueue

typedef typedefG_BEGIN_DECLS struct _GAsyncQueueGAsyncQueue

g_async_queue_new ( void )

IMPORT_C GAsyncQueue *g_async_queue_new(void)

g_async_queue_new:

Creates a new asynchronous queue with the initial reference count of 1.

Return value: the new GAsyncQueue.

g_async_queue_new_full ( GDestroyNotify )

IMPORT_C GAsyncQueue *g_async_queue_new_full(GDestroyNotifyitem_free_func)

g_async_queue_new_full: : function to free queue elements

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.

Return value: the new GAsyncQueue.

Since: 2.16

g_async_queue_lock ( GAsyncQueue * )

IMPORT_C voidg_async_queue_lock(GAsyncQueue *queue)

g_async_queue_lock: : a GAsyncQueue.

Acquires the 's lock. After that you can only call the <function>g_async_queue_*_unlocked()</function> function variants on that . Otherwise it will deadlock.

g_async_queue_unlock ( GAsyncQueue * )

IMPORT_C voidg_async_queue_unlock(GAsyncQueue *queue)

g_async_queue_unlock: : a GAsyncQueue.

Releases the queue's lock.

g_async_queue_ref ( GAsyncQueue * )

IMPORT_C GAsyncQueue *g_async_queue_ref(GAsyncQueue *queue)

g_async_queue_ref: : a GAsyncQueue.

Increases the reference count of the asynchronous by 1. You do not need to hold the lock to call this function.

Returns: the that was passed in (since 2.6)

g_async_queue_unref ( GAsyncQueue * )

IMPORT_C voidg_async_queue_unref(GAsyncQueue *queue)

g_async_queue_unref: : a GAsyncQueue.

Decreases the reference count of the asynchronous by 1. If the reference count went to 0, the will be destroyed and the memory allocated will be freed. So you are not allowed to use the afterwards, as it might have disappeared. You do not need to hold the lock to call this function.

g_async_queue_ref_unlocked ( GAsyncQueue * )

IMPORT_C voidg_async_queue_ref_unlocked(GAsyncQueue *queue)

g_async_queue_ref_unlocked: : a GAsyncQueue.

Increases the reference count of the asynchronous by 1.

: Since 2.8, reference counting is done atomically so g_async_queue_ref() can be used regardless of the 's lock.

g_async_queue_unref_and_unlock ( GAsyncQueue * )

IMPORT_C voidg_async_queue_unref_and_unlock(GAsyncQueue *queue)

g_async_queue_unref_and_unlock: : a GAsyncQueue.

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

: Since 2.8, reference counting is done atomically so g_async_queue_unref() can be used regardless of the 's lock.

g_async_queue_push ( GAsyncQueue *, gpointer )

IMPORT_C voidg_async_queue_push(GAsyncQueue *queue,
gpointerdata
)

g_async_queue_push: : a GAsyncQueue. : to push into the .

Pushes the into the . must not be NULL.

g_async_queue_push_unlocked ( GAsyncQueue *, gpointer )

IMPORT_C voidg_async_queue_push_unlocked(GAsyncQueue *queue,
gpointerdata
)

g_async_queue_push_unlocked: : a GAsyncQueue. : to push into the .

Pushes the into the . must not be NULL. This function must be called while holding the 's lock.

g_async_queue_push_sorted ( GAsyncQueue *, gpointer, GCompareDataFunc, gpointer )

IMPORT_C voidg_async_queue_push_sorted(GAsyncQueue *queue,
gpointerdata,
GCompareDataFuncfunc,
gpointeruser_data
)

g_async_queue_push_sorted: : a GAsyncQueue : the to push into the : the GCompareDataFunc is used to sort . This function is passed two elements of the . The function should return 0 if they are equal, a negative value if the first element should be higher in the or a positive value if the first element should be lower in the than the second element. : user data passed to .

Inserts into using to determine the new position.

This function requires that the is sorted before pushing on new elements.

This function will lock before it sorts the queue and unlock it when it is finished.

For an example of see g_async_queue_sort().

Since: 2.10

g_async_queue_push_sorted_unlocked ( GAsyncQueue *, gpointer, GCompareDataFunc, gpointer )

IMPORT_C voidg_async_queue_push_sorted_unlocked(GAsyncQueue *queue,
gpointerdata,
GCompareDataFuncfunc,
gpointeruser_data
)

g_async_queue_push_sorted_unlocked: : a GAsyncQueue : the to push into the : the GCompareDataFunc is used to sort . This function is passed two elements of the . The function should return 0 if they are equal, a negative value if the first element should be higher in the or a positive value if the first element should be lower in the than the second element. : user data passed to .

Inserts into using to determine the new position.

This function requires that the is sorted before pushing on new elements.

This function is called while holding the 's lock.

For an example of see g_async_queue_sort().

Since: 2.10

g_async_queue_pop ( GAsyncQueue * )

IMPORT_C gpointerg_async_queue_pop(GAsyncQueue *queue)

g_async_queue_pop: : a GAsyncQueue.

Pops data from the . This function blocks until data become available.

Return value: data from the queue.

g_async_queue_pop_unlocked ( GAsyncQueue * )

IMPORT_C gpointerg_async_queue_pop_unlocked(GAsyncQueue *queue)

g_async_queue_pop_unlocked: : a GAsyncQueue.

Pops data from the . This function blocks until data become available. This function must be called while holding the 's lock.

Return value: data from the queue.

g_async_queue_try_pop ( GAsyncQueue * )

IMPORT_C gpointerg_async_queue_try_pop(GAsyncQueue *queue)

g_async_queue_try_pop: : a GAsyncQueue.

Tries to pop data from the . If no data is available, NULL is returned.

Return value: data from the queue or NULL, when no data is available immediately.

g_async_queue_try_pop_unlocked ( GAsyncQueue * )

IMPORT_C gpointerg_async_queue_try_pop_unlocked(GAsyncQueue *queue)

g_async_queue_try_pop_unlocked: : a GAsyncQueue.

Tries to pop data from the . If no data is available, NULL is returned. This function must be called while holding the 's lock.

Return value: data from the queue or NULL, when no data is available immediately.

g_async_queue_timed_pop ( GAsyncQueue *, GTimeVal * )

IMPORT_C gpointerg_async_queue_timed_pop(GAsyncQueue *queue,
GTimeVal *end_time
)

g_async_queue_timed_pop: : a GAsyncQueue. : a GTimeVal, determining the final time.

Pops data from the . If no data is received before , NULL is returned.

To easily calculate a combination of g_get_current_time() and g_time_val_add() can be used.

Return value: data from the queue or NULL, when no data is received before .

g_async_queue_timed_pop_unlocked ( GAsyncQueue *, GTimeVal * )

IMPORT_C gpointerg_async_queue_timed_pop_unlocked(GAsyncQueue *queue,
GTimeVal *end_time
)

g_async_queue_timed_pop_unlocked: : a GAsyncQueue. : a GTimeVal, determining the final time.

Pops data from the . If no data is received before , NULL is returned. This function must be called while holding the 's lock.

To easily calculate a combination of g_get_current_time() and g_time_val_add() can be used.

Return value: data from the queue or NULL, when no data is received before .

g_async_queue_length ( GAsyncQueue * )

IMPORT_C gintg_async_queue_length(GAsyncQueue *queue)

g_async_queue_length: : a GAsyncQueue.

Returns the length of the queue, negative values mean waiting threads, positive values mean available entries in the . 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.

Return value: the length of the .

g_async_queue_length_unlocked ( GAsyncQueue * )

IMPORT_C gintg_async_queue_length_unlocked(GAsyncQueue *queue)

g_async_queue_length_unlocked: : a GAsyncQueue.

Returns the length of the queue, negative values mean waiting threads, positive values mean available entries in the . 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 's lock.

Return value: the length of the .

g_async_queue_sort ( GAsyncQueue *, GCompareDataFunc, gpointer )

IMPORT_C voidg_async_queue_sort(GAsyncQueue *queue,
GCompareDataFuncfunc,
gpointeruser_data
)

g_async_queue_sort: : a GAsyncQueue : the GCompareDataFunc is used to sort . This function is passed two elements of the . The function should return 0 if they are equal, a negative value if the first element should be higher in the or a positive value if the first element should be lower in the than the second element. : user data passed to

Sorts using .

This function will lock before it sorts the queue and unlock it when it is finished.

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: |[ gint32 id1; gint32 id2;

id1 = GPOINTER_TO_INT (element1); id2 = GPOINTER_TO_INT (element2);

return (id1 > id2 ? +1 : id1 == id2 ? 0 : -1); ]|

Since: 2.10

g_async_queue_sort_unlocked ( GAsyncQueue *, GCompareDataFunc, gpointer )

IMPORT_C voidg_async_queue_sort_unlocked(GAsyncQueue *queue,
GCompareDataFuncfunc,
gpointeruser_data
)

g_async_queue_sort_unlocked: : a GAsyncQueue : the GCompareDataFunc is used to sort . This function is passed two elements of the . The function should return 0 if they are equal, a negative value if the first element should be higher in the or a positive value if the first element should be lower in the than the second element. : user data passed to

Sorts using .

This function is called while holding the 's lock.

Since: 2.10

_g_async_queue_get_mutex ( GAsyncQueue * )

GMutex *_g_async_queue_get_mutex(GAsyncQueue *queue)