rpa_queue
rpa_queue copied to clipboard
Peek function and size reporting macros changes.
I have added peek function taking the element without removing it from the queue. Also moved and added some size reporting functions
/**
* peek an object from the queue without removing it from the queue, blocking if the queue is already empty
*
* @param queue the queue
* @param data the data
* @param wait_ms milliseconds to wait
* @returns RPA_EINTR the blocking was interrupted (try again)
* @returns RPA_EOF if the queue has been terminated
* @returns RPA_SUCCESS on a successful pop
*/
bool rpa_queue_timedpeek(rpa_queue_t *queue, void **data, int wait_ms);
/**
* @brief Macro to check if the rpa_queue_t is full.
*
* This macro checks if the number of elements in the queue is equal to the maximum
* size of the queue, indicating that the queue is full.
*
* @param queue Pointer to the rpa_queue_t instance.
* @return 1 if the queue is full, 0 otherwise.
*/
#define rpa_queue_full(queue) ((queue)->nelts == (queue)->bounds)
/**
* @brief Macro to get the number of free slots in the rpa_queue_t.
*
* This macro calculates the number of free slots in the queue by subtracting
* the current number of elements from the maximum size of the queue.
*
* @param queue Pointer to the rpa_queue_t instance.
* @return The number of free slots in the queue.
*/
#define rpa_queue_get_free(queue) (((queue)->bounds) - ((queue)->nelts))
/**
* @brief Macro to get the number of taken slots in the rpa_queue_t.
*
* This macro retrieves the current number of elements in the queue, indicating
* the number of slots that have been taken.
*
* @param queue Pointer to the rpa_queue_t instance.
* @return The number of taken slots in the queue.
*/
#define rpa_queue_get_taken(queue) ((queue)->nelts)
/**
* @brief Macro to check if the rpa_queue_t is empty.
*
* This macro checks if the number of elements in the queue is zero, indicating
* that the queue is empty.
*
* @param queue Pointer to the rpa_queue_t instance.
* @return 1 if the queue is empty, 0 otherwise.
*/
#define rpa_queue_empty(queue) ((queue)->nelts == 0)