Qore Programming Language Reference Manual
1.12.1
|
Queue objects provide a blocking, thread-safe message-passing object to Qore programs More...
Public Member Methods | |
nothing | clear () |
Clears the Queue of all data. More... | |
clearError () | |
clears the error setting from the Queue; if error information is set, then after this call, the Queue is usable again More... | |
constructor (int max=-1) | |
Creates the Queue object. More... | |
copy () | |
Creates a new Queue object with the same elements and maximum size as the original. | |
destructor () | |
Destroys the Queue object. More... | |
bool | empty () |
Returns True if the Queue is empty, False if not. More... | |
auto | get (timeout timeout_ms=0) |
Blocks until at least one entry is available on the queue, then returns the first entry in the queue. If a timeout occurs, an exception is thrown. If the timeout value equal to zero, then the call does not timeout until data is available, while negative timeout values cause the call to timeout immediately if the call would otherwise block. More... | |
int | getReadWaiting () |
Returns the number of threads currently blocked on this queue for reading. More... | |
int | getWaiting () |
Returns the number of threads currently blocked on this queue for reading. More... | |
int | getWriteWaiting () |
Returns the number of threads currently blocked on this queue for writing. More... | |
nothing | insert (auto arg, timeout timeout_ms=0) |
Inserts a value at the beginning of the queue. More... | |
int | max () |
Returns the upper limit of the number of elements in the Queue. More... | |
auto | pop (timeout timeout_ms=0) |
Blocks until at least one entry is available on the queue, then returns the last entry in the queue. If a timeout occurs, an exception is thrown. If the timeout is less than or equal to zero, then the call does not timeout until data is available. More... | |
nothing | push (auto arg, timeout timeout_ms=0) |
Pushes a value on the end of the queue. More... | |
setError (string err, string desc) | |
sets an error status on the Queue and clears the Queue; while a Queue object has an error status, any write operations to the queue will fail and cause an exception to be raised with the information provided to this method More... | |
int | size () |
Returns the number of elements in the Queue. More... | |
Queue objects provide a blocking, thread-safe message-passing object to Qore programs
Queue objects can also be used as a stack or as a blocking message channel, if a maximum size is given to Queue::constructor() when the object is created.
In this case when the Queue is full, adding new elements to the Queue will block until the Queue shrinks below the maximum size.
All read and write methods to Queue also take timeout values; if a timeout occurs a QUEUE-TIMEOUT
exception is thrown.
Queues can be atomically flagged with an error status by calling Queue::setError(). This method will cause any write operations on the Queue to fail with the error information provided with this call. Calling Queue::clearError() causes the error status to be removed and allows the Queue to be usable again.
nothing Qore::Thread::Queue::clear | ( | ) |
Qore::Thread::Queue::clearError | ( | ) |
clears the error setting from the Queue; if error information is set, then after this call, the Queue is usable again
Qore::Thread::Queue::constructor | ( | int | max = -1 | ) |
Creates the Queue object.
max | the maximum size of the Queue; -1 means no limit; if 0 or a negative number other than -1 is passed then a QUEUE-SIZE-ERROR exception will be thrown |
QUEUE-SIZE-ERROR | the size cannot be zero or any negative number except for -1 or a number that cannot fit in 32 bits (signed) |
Qore::Thread::Queue::destructor | ( | ) |
Destroys the Queue object.
QUEUE-ERROR | The queue was deleted while at least one thread was blocked on it |
bool Qore::Thread::Queue::empty | ( | ) |
auto Qore::Thread::Queue::get | ( | timeout | timeout_ms = 0 | ) |
Blocks until at least one entry is available on the queue, then returns the first entry in the queue. If a timeout occurs, an exception is thrown. If the timeout value equal to zero, then the call does not timeout until data is available, while negative timeout values cause the call to timeout immediately if the call would otherwise block.
timeout_ms | a timeout value to wait for data to become available on the queue; integers are interpreted as milliseconds; relative date/time values are interpreted literally with a maximum resolution of milliseconds. A negative timeout value causes the call to time out immediately with a QUEUE-TIMEOUT exception if the call would otherwise block. If a positive timeout argument is passed, and no data is available in the timeout period, a "QUEUE-TIMEOUT" exception is thrown. If no value or a value that converts to integer 0 is passed as the argument, then the call does not timeout until data is available on the queue. |
"QUEUE-TIMEOUT"
exception on timeout, in order to enable the case where NOTHING was pushed on the queue to be differentiated from a timeoutQUEUE-TIMEOUT | The timeout value was exceeded |
QUEUE-ERROR | The queue was deleted while at least one thread was blocked on it |
QUEUE-TIMEOUT-ERROR | the timeout value must be >= -2147483648 and <= 2147483647 or this exception is thrown |
int Qore::Thread::Queue::getReadWaiting | ( | ) |
Returns the number of threads currently blocked on this queue for reading.
This is a "synonym" for Queue::getWaiting()
int Qore::Thread::Queue::getWaiting | ( | ) |
Returns the number of threads currently blocked on this queue for reading.
This is a "synonym" for Queue::getReadWaiting()
int Qore::Thread::Queue::getWriteWaiting | ( | ) |
Returns the number of threads currently blocked on this queue for writing.
nothing Qore::Thread::Queue::insert | ( | auto | arg, |
timeout | timeout_ms = 0 |
||
) |
Inserts a value at the beginning of the queue.
arg | value to be put on the queue |
timeout_ms | a timeout value to wait for a free entry to become available on the queue; integers are interpreted as milliseconds; relative date/time values are interpreted literally with a maximum resolution of milliseconds. A negative timeout value causes the call to time out immediately with a QUEUE-TIMEOUT exception if the call would otherwise block. If a positive timeout argument is passed, and the queue has already reached its maximum size and does not go below the maximum size within the timeout period, a "QUEUE-TIMEOUT" exception is thrown. If no value or a value that converts to integer 0 is passed as the argument, then the call does not timeout until a slot becomes available on the queue. Queue slots are only limited if a maximum size is passed to Queue::constructor(). |
QUEUE-TIMEOUT | The timeout value was exceeded |
QUEUE-ERROR | The queue was deleted while at least one thread was blocked on it |
QUEUE-TIMEOUT-ERROR | the timeout value must be >= -2147483648 and <= 2147483647 or this exception is thrown |
int Qore::Thread::Queue::max | ( | ) |
Returns the upper limit of the number of elements in the Queue.
auto Qore::Thread::Queue::pop | ( | timeout | timeout_ms = 0 | ) |
Blocks until at least one entry is available on the queue, then returns the last entry in the queue. If a timeout occurs, an exception is thrown. If the timeout is less than or equal to zero, then the call does not timeout until data is available.
timeout_ms | a timeout value to wait for data to become available on the queue; integers are interpreted as milliseconds; relative date/time values are interpreted literally with a maximum resolution of milliseconds. A negative timeout value causes the call to time out immediately with a QUEUE-TIMEOUT exception if the call would otherwise block. If a positive timeout argument is passed, and no data is available in the timeout period, a "QUEUE-TIMEOUT" exception is thrown. If no value or a value that converts to integer 0 is passed as the argument, then the call does not timeout until data is available on the queue. |
"QUEUE-TIMEOUT"
exception on timeout, in order to enable the case where NOTHING was pushed on the queue to be differentiated from a timeoutQUEUE-TIMEOUT | The timeout value was exceeded |
QUEUE-ERROR | The queue was deleted while at least one thread was blocked on it |
QUEUE-TIMEOUT-ERROR | the timeout value must be >= -2147483648 and <= 2147483647 or this exception is thrown |
nothing Qore::Thread::Queue::push | ( | auto | arg, |
timeout | timeout_ms = 0 |
||
) |
Pushes a value on the end of the queue.
arg | value to be put on the queue |
timeout_ms | a timeout value to wait for a free entry to become available on the queue; integers are interpreted as milliseconds; relative date/time values are interpreted literally with a maximum resolution of milliseconds. A negative timeout value causes the call to time out immediately with a QUEUE-TIMEOUT exception if the call would otherwise block. If a positive timeout argument is passed, and the queue has already reached its maximum size and does not go below the maximum size within the timeout period, a "QUEUE-TIMEOUT" exception is thrown. If no value or a value that converts to integer 0 is passed as the argument, then the call does not timeout until a slot becomes available on the queue. Queue slots are only limited if a maximum size is passed to Queue::constructor(). |
QUEUE-TIMEOUT | The timeout value was exceeded |
QUEUE-ERROR | The queue was deleted while at least one thread was blocked on it |
QUEUE-TIMEOUT-ERROR | the timeout value must be >= -2147483648 and <= 2147483647 or this exception is thrown |
sets an error status on the Queue and clears the Queue; while a Queue object has an error status, any write operations to the queue will fail and cause an exception to be raised with the information provided to this method
err | the exception error code string |
desc | the exception description string |
Any threads blocked on this Queue will be woken up immediately and have the given exception thrown
int Qore::Thread::Queue::size | ( | ) |
Returns the number of elements in the Queue.