cthreadcomm · Section 3
cdynmq_msg_count
NAME
cdynmq_msg_count - number of messages that a dynamic queue holds now
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h> size_t cdynmq_msg_count(cdynmq *dq);
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. A dynamic queue grows on demand and has no fixed capacity, so the count depends only on how many messages the producers have sent and the consumers have not received yet.
PARAMETERS
dq Dynamic queue to ask
RETURN VALUE
The message count, or ccol_invalid_size if dq is NULL.
NOTES
The call is O(1) and thread-safe.
WARNINGS
The value is only a snapshot, because another thread can send or receive right after the call returns. Do not use it to decide that a later receive won't block; if you need a receive that doesn't block, call cdynmq_try_recv().
SEE ALSO
cdynmq_send(3), cdynmq_recv(3), cdynmq_try_recv(3), ccircq_msg_count(3)