cthreadcomm · Section 3
cdynmq_disable_sending
NAME
cdynmq_disable_sending - turn off sends on a dynamic queue
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h> ccol_retval cdynmq_disable_sending(cdynmq *dq);
DESCRIPTION
Marks the queue as closed to new sends, so every later send returns ccol_not_permitted until somebody calls cdynmq_enable_sending(). A refused send keeps the ownership of its own msg->data. A dynamic queue grows on demand, so no sender ever waits for room the way it does on a circular queue, and there are no blocked senders to wake here. While its sends are off, the queue counts as ready for the write direction, the same way a pipe whose reader has gone is ready for POLLOUT. For that reason the call wakes every write-direction waiter on the queue, meaning a cselect() call, a cselect_timed() call or a ceventloop registration. A cselect() call returns the index of the queue, and the cdynmq_send() that the caller makes next returns ccol_not_permitted at once. A ceventloop registration gets one on_writable call, and a write registration added while sends are off gets one as soon as it is added. After that the registration is called again only for a later event on the queue, such as a receive or another change of the send state, so it doesn't spin. A write waiter that starts while sends are off returns at once too. Receives are not affected. The messages already in the queue stay there and are received the normal way, so this is the natural way to close the producer side and let a consumer drain whatever is left.
PARAMETERS
dq Dynamic queue that gets sends turned off
RETURN VALUE
ccol_success - Sends are off ccol_invalid_args - dq is NULL
NOTES
To turn sends back on, call cdynmq_enable_sending(). The function is thread-safe.
SEE ALSO
cdynmq_enable_sending(3), cdynmq_send(3), cdynmq_msg_count(3), ccircq_disable_sending(3)