Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peek function and size reporting macros changes. #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

arduzilla
Copy link

I have added peek function taking the element without removing it from the queue. Also moved and added some size reporting functions

Moved size reporting macros to the header file
1. Moved size reopting macros from the C file
2. Added macros giving number of elements taken and free
3. Added peek function prototy
@arduzilla
Copy link
Author

/**
 * 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)

rpa_queue.h Outdated
* @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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, but can you do this with functions rather than macros? That would allow keeping the structure private (hidden in the .c file).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants