Class (GI Struct)

GLib-2.0GLibAsyncQueueAbstract

An opaque data structure which represents an asynchronous queue.

It should only be accessed through the g_async_queue_* functions.

Index

Constructors

Properties

$gtype: GType<AsyncQueue>

Methods

  • Returns the length of the queue.

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

    Returns number

    the length of the queue

  • Returns the length of the queue.

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

    This function must be called while holding the queue's lock.

    Returns number

    the length of the queue.

  • Acquires the queue's lock. If another thread is already holding the lock, this call will block until the lock becomes available.

    Call g_async_queue_unlock() to drop the lock again.

    While holding the lock, you can only call the g_async_queue_*_unlocked() functions on queue. Otherwise, deadlock may occur.

    Returns void

  • Pops data from the queue. If queue is empty, this function blocks until data becomes available.

    Returns any

    data from the queue

  • Pops data from the queue. If queue is empty, this function blocks until data becomes available.

    This function must be called while holding the queue's lock.

    Returns any

    data from the queue.

  • Pushes the data into the queue.

    The data parameter must not be null.

    Parameters

    • data: any

      data to push onto the queue

    Returns void

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

    Parameters

    • item: any

      data to push into the queue

    Returns void

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

    This function must be called while holding the queue's lock.

    Parameters

    • item: any

      data to push into the queue

    Returns void

  • Inserts data into queue using func to determine the new position.

    This function requires that the queue is sorted before pushing on new elements, see g_async_queue_sort().

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

    For an example of func see g_async_queue_sort().

    Parameters

    Returns void

  • Inserts data into queue using func to determine the new position.

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

    This function requires that the queue is sorted before pushing on new elements, see g_async_queue_sort().

    This function must be called while holding the queue's lock.

    For an example of func see g_async_queue_sort().

    Parameters

    Returns void

  • Pushes the data into the queue.

    The data parameter must not be null.

    This function must be called while holding the queue's lock.

    Parameters

    • data: any

      data to push onto the queue

    Returns void

  • Remove an item from the queue.

    Parameters

    • item: any

      the data to remove from the queue

    Returns boolean

    true if the item was removed

  • Remove an item from the queue.

    This function must be called while holding the queue's lock.

    Parameters

    • item: any

      the data to remove from the queue

    Returns boolean

    true if the item was removed

  • Sorts queue using func.

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

    This function will lock queue 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);

    Parameters

    Returns void

  • Sorts queue using func.

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

    This function must be called while holding the queue's lock.

    Parameters

    Returns void

  • Pops data from the queue. If the queue is empty, blocks until end_time or until data becomes available.

    If no data is received before end_time, null is returned.

    To easily calculate end_time, a combination of g_get_real_time() and g_time_val_add() can be used.

    Parameters

    Returns any

    data from the queue or null, when no data is received before end_time.

  • Pops data from the queue. If the queue is empty, blocks until end_time or until data becomes available.

    If no data is received before end_time, null is returned.

    To easily calculate end_time, a combination of g_get_real_time() and g_time_val_add() can be used.

    This function must be called while holding the queue's lock.

    Parameters

    Returns any

    data from the queue or null, when no data is received before end_time.

  • Pops data from the queue. If the queue is empty, blocks for timeout microseconds, or until data becomes available.

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

    Parameters

    • timeout: number

      the number of microseconds to wait

    Returns any

    data from the queue or null, when no data is received before the timeout.

  • Pops data from the queue. If the queue is empty, blocks for timeout microseconds, or until data becomes available.

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

    This function must be called while holding the queue's lock.

    Parameters

    • timeout: number

      the number of microseconds to wait

    Returns any

    data from the queue or null, when no data is received before the timeout.

  • Tries to pop data from the queue. If no data is available, null is returned.

    Returns any

    data from the queue or null, when no data is available immediately.

  • Tries to pop data from the queue. If no data is available, null is returned.

    This function must be called while holding the queue's lock.

    Returns any

    data from the queue or null, when no data is available immediately.

  • Releases the queue's lock.

    Calling this function when you have not acquired the with g_async_queue_lock() leads to undefined behaviour.

    Returns void

  • Decreases the reference count of the asynchronous queue by 1.

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

    Returns void

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

    Returns void