C Collections

cthreadcomm · Section 3

ccircq_disable_sending

ccircq_disable_sending - turn off sends on a circular queue

C Collections (libccollections, -lccollections)

#include <ccollections/cthreadcomm.h>
 
ccol_retval ccircq_disable_sending(ccircq *cq);

Marks the queue as closed to new sends and wakes every thread that is
blocked in ccircq_send() or ccircq_timed_send() waiting
for free space. Each of those threads checks the flag again when it
wakes up and returns ccol_not_permitted without putting its message
into the queue, so it keeps the ownership of its own msg->data.
 
Every later send (ccircq_send(), ccircq_try_send() or
ccircq_timed_send()) returns ccol_not_permitted as well, until
somebody calls ccircq_enable_sending().
 
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.
 
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 also 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
ccircq_try_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, even when the queue is
full.

cq   Circular queue that gets sends turned off

ccol_success       - Sends are off
ccol_invalid_args  - cq is NULL

Blocked senders are woken at once with a broadcast. To turn sends back
on, call ccircq_enable_sending(). The function is thread-safe.

ccircq_enable_sending(3), ccircq_send(3), ccircq_try_send(3), ccircq_timed_send(3), ccircq_msg_count(3)