cthreadcomm · Section 3
ccircq_msg_count
NAME
ccircq_msg_count - get the current message count of a circular queue
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h> size_t ccircq_msg_count(ccircq *cq);
DESCRIPTION
Returns the number of messages that the queue holds at the moment of the call. The count is read under the queue's lock, so it is a consistent value and never a torn read. It is still only a snapshot. Another thread can send or receive right after the lock is released, so by the time you look at the value it describes a moment that has passed. It is fine for reports and for a drain loop, but to find out whether the queue has room or holds a message, call ccircq_try_send() or ccircq_try_recv(), which check and act in one step that nothing can come between.
PARAMETERS
cq Circular queue to ask
RETURN VALUE
The number of messages in the queue, or ccol_invalid_size ((size_t)-1) when cq is NULL.
NOTES
Zero is an ordinary result and means that the queue is empty. Only ccol_invalid_size reports an error.
SEE ALSO
ccircq_try_recv(3), ccircq_try_send(3), ccircq_disable_sending(3), cchan_msg_count(3)