Class AsyncQueue
- All Implemented Interfaces:
Proxy
It should only be accessed through the g_async_queue_* functions.
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncQueue(MemorySegment address) Create a AsyncQueue proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionintlength()Returns the length of the queue.intReturns the length of the queue.voidlock()Acquires thequeue'slock.static AsyncQueuenew_()Creates a new asynchronous queue.static AsyncQueuenewFull()Creates a new asynchronous queue 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.pop()Pops data from thequeue.If this AsyncQueue is empty, this function blocks until data becomes available.Pops data from thequeue.If this AsyncQueue is empty, this function blocks until data becomes available.voidpush(MemorySegment data) Pushes thedatainto thequeue.voidpushFront(MemorySegment item) Pushes theiteminto thequeue.itemmust not benull.voidPushes theiteminto thequeue.itemmust not benull.voidpushSorted(MemorySegment data, @Nullable CompareDataFunc func) Insertsdatainto this AsyncQueue usingfuncto determine the new position.voidpushSortedUnlocked(MemorySegment data, @Nullable CompareDataFunc func) Insertsdatainto this AsyncQueue usingfuncto determine the new position.voidpushUnlocked(MemorySegment data) Pushes thedatainto thequeue.ref()Increases the reference count of the asynchronous this AsyncQueue by 1.voidDeprecated.Reference counting is done atomically.booleanremove(MemorySegment item) Remove an item from the queue.booleanremoveUnlocked(MemorySegment item) Remove an item from the queue.voidsort(@Nullable CompareDataFunc func) Sorts this AsyncQueue usingfunc.voidsortUnlocked(@Nullable CompareDataFunc func) Sorts this AsyncQueue usingfunc.@Nullable MemorySegmentDeprecated.use g_async_queue_timeout_pop().@Nullable MemorySegmenttimedPopUnlocked(TimeVal endTime) Deprecated.use g_async_queue_timeout_pop_unlocked().@Nullable MemorySegmenttimeoutPop(long timeout) Pops data from thequeue.If the queue is empty, blocks fortimeoutmicroseconds, or until data becomes available.@Nullable MemorySegmenttimeoutPopUnlocked(long timeout) Pops data from thequeue.If the queue is empty, blocks fortimeoutmicroseconds, or until data becomes available.@Nullable MemorySegmenttryPop()Tries to pop data from thequeue.If no data is available,nullis returned.@Nullable MemorySegmentTries to pop data from thequeue.If no data is available,nullis returned.voidunlock()Releases the queue's lock.voidunref()Decreases the reference count of the asynchronous this AsyncQueue by 1.voidDeprecated.Reference counting is done atomically.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
AsyncQueue
Create a AsyncQueue proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
-
Method Details
-
new_
Creates a new asynchronous queue.- Returns:
- a new
GAsyncQueue. Free with g_async_queue_unref()
-
newFull
Creates a new asynchronous queue 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.- Returns:
- a new
GAsyncQueue. Free with g_async_queue_unref() - Since:
- 2.16
-
length
public int length()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:
- the length of the this AsyncQueue
-
lengthUnlocked
public int lengthUnlocked()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'slock.- Returns:
- the length of the
queue.
-
lock
public void lock()Acquires thequeue'slock. 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. -
pop
Pops data from thequeue.If this AsyncQueue is empty, this function blocks until data becomes available.- Returns:
- data from the queue
-
popUnlocked
Pops data from thequeue.If this AsyncQueue is empty, this function blocks until data becomes available.This function must be called while holding the
queue'slock.- Returns:
- data from the queue.
-
push
Pushes thedatainto thequeue.The
dataparameter must not benull.- Parameters:
data- data to push onto the this AsyncQueue
-
pushFront
Pushes theiteminto thequeue.itemmust not benull. 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- data to push into the this AsyncQueue- Since:
- 2.46
-
pushFrontUnlocked
Pushes theiteminto thequeue.itemmust not benull. 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'slock.- Parameters:
item- data to push into the this AsyncQueue- Since:
- 2.46
-
pushSorted
Insertsdatainto this AsyncQueue usingfuncto determine the new position.This function requires that the this AsyncQueue is sorted before pushing on new elements, see g_async_queue_sort().
This function will lock this AsyncQueue before it sorts the queue and unlock it when it is finished.
For an example of
funcsee g_async_queue_sort().- Parameters:
data- thedatato push into the this AsyncQueuefunc- theGCompareDataFuncis used to sort this AsyncQueue- Since:
- 2.10
-
pushSortedUnlocked
Insertsdatainto this AsyncQueue usingfuncto determine the new position.The sort function
funcis passed two elements of thequeue.It should return 0 if they are equal, a negative value if the first element should be higher in the this AsyncQueue or a positive value if the first element should be lower in the this AsyncQueue than the second element.This function requires that the this AsyncQueue is sorted before pushing on new elements, see g_async_queue_sort().
This function must be called while holding the
queue'slock.For an example of
funcsee g_async_queue_sort().- Parameters:
data- the data to push into the this AsyncQueuefunc- theGCompareDataFuncis used to sort this AsyncQueue- Since:
- 2.10
-
pushUnlocked
Pushes thedatainto thequeue.The
dataparameter must not benull.This function must be called while holding the
queue'slock.- Parameters:
data- data to push onto the this AsyncQueue
-
ref
Increases the reference count of the asynchronous this AsyncQueue by 1. You do not need to hold the lock to call this function.- Returns:
- the this AsyncQueue that was passed in (since 2.6)
-
refUnlocked
Deprecated.Reference counting is done atomically. so g_async_queue_ref() can be used regardless of thequeue'slock.Increases the reference count of the asynchronous this AsyncQueue by 1. -
remove
Remove an item from the queue.- Parameters:
item- the data to remove from the this AsyncQueue- Returns:
trueif the item was removed- Since:
- 2.46
-
removeUnlocked
Remove an item from the queue.This function must be called while holding the
queue'slock.- Parameters:
item- the data to remove from the this AsyncQueue- Returns:
trueif the item was removed- Since:
- 2.46
-
sort
Sorts this AsyncQueue usingfunc.The sort function
funcis passed two elements of thequeue.It should return 0 if they are equal, a negative value if the first element should be higher in the this AsyncQueue or a positive value if the first element should be lower in the this AsyncQueue than the second element.This function will lock this AsyncQueue 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:
func- theGCompareDataFuncis used to sort this AsyncQueue- Since:
- 2.10
-
sortUnlocked
Sorts this AsyncQueue usingfunc.The sort function
funcis passed two elements of thequeue.It should return 0 if they are equal, a negative value if the first element should be higher in the this AsyncQueue or a positive value if the first element should be lower in the this AsyncQueue than the second element.This function must be called while holding the
queue'slock.- Parameters:
func- theGCompareDataFuncis used to sort this AsyncQueue- Since:
- 2.10
-
timedPop
Deprecated.use g_async_queue_timeout_pop().Pops data from thequeue.If the queue is empty, blocks untilendTimeor until data becomes available.If no data is received before
endTime,nullis returned.To easily calculate
endTime,a combination of g_get_real_time() and g_time_val_add() can be used.- Parameters:
endTime- aGTimeVal, determining the final time- Returns:
- data from the queue or
null, when no data is received beforeendTime.
-
timedPopUnlocked
Deprecated.use g_async_queue_timeout_pop_unlocked().Pops data from thequeue.If the queue is empty, blocks untilendTimeor until data becomes available.If no data is received before
endTime,nullis returned.To easily calculate
endTime,a combination of g_get_real_time() and g_time_val_add() can be used.This function must be called while holding the
queue'slock.- Parameters:
endTime- aGTimeVal, determining the final time- Returns:
- data from the queue or
null, when no data is received beforeendTime.
-
timeoutPop
Pops data from thequeue.If the queue is empty, blocks fortimeoutmicroseconds, or until data becomes available.If no data is received before the timeout,
nullis returned.- Parameters:
timeout- the number of microseconds to wait- Returns:
- data from the queue or
null, when no data is received before the timeout.
-
timeoutPopUnlocked
Pops data from thequeue.If the queue is empty, blocks fortimeoutmicroseconds, or until data becomes available.If no data is received before the timeout,
nullis returned.This function must be called while holding the
queue'slock.- Parameters:
timeout- the number of microseconds to wait- Returns:
- data from the queue or
null, when no data is received before the timeout.
-
tryPop
Tries to pop data from thequeue.If no data is available,nullis returned.- Returns:
- data from the queue or
null, when no data is available immediately.
-
tryPopUnlocked
Tries to pop data from thequeue.If no data is available,nullis returned.This function must be called while holding the
queue'slock.- Returns:
- data from the queue or
null, when no data is available immediately.
-
unlock
public void unlock()Releases the queue's lock.Calling this function when you have not acquired the with g_async_queue_lock() leads to undefined behaviour.
-
unref
public void unref()Decreases the reference count of the asynchronous this AsyncQueue by 1.If the reference count went to 0, the this AsyncQueue will be destroyed and the memory allocated will be freed. So you are not allowed to use the this AsyncQueue afterwards, as it might have disappeared. You do not need to hold the lock to call this function.
-
unrefAndUnlock
Deprecated.Reference counting is done atomically. so g_async_queue_unref() can be used regardless of thequeue'slock.Decreases the reference count of the asynchronous this AsyncQueue by 1 and releases the lock. This function must be called while holding thequeue'slock. If the reference count went to 0, the this AsyncQueue will be destroyed and the memory allocated will be freed.
-