C Collections

cthreadcomm · Section 3

cdynmq_msg_count

cdynmq_msg_count - number of messages that a dynamic queue holds now

C Collections (libccollections, -lccollections)

#include <ccollections/cthreadcomm.h>
 
size_t cdynmq_msg_count(cdynmq *dq);

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.

dq   Dynamic queue to ask

The message count, or ccol_invalid_size if dq is NULL.

The call is O(1) and thread-safe.

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().

cdynmq_send(3), cdynmq_recv(3), cdynmq_try_recv(3), ccircq_msg_count(3)