C Collections

cthreadcomm · Section 3

ccircq_create

ccircq_create - create a circular queue

C Collections (libccollections, -lccollections)

#include <ccollections/cthreadcomm.h>
 
ccircq_create(max_size, err_str);

Creates a fixed-size queue on top of a circular buffer. A send on a
full queue blocks until there is free space. Memory comes from the
standard malloc and free.
 
It is the same as calling ccircq_create_mp() with NULL
memory management procedures.

max_size  Maximum number of messages that the queue can hold, from 1
          to SIZE_MAX / sizeof(cmessage). A larger value is
          refused, because the queue lives in one array of
          max_size * sizeof(cmessage) bytes and that product would
          overflow.
err_str   Optional pointer that gets an error string on failure

A pointer to the new circular queue, or NULL on failure.

All operations on this queue are thread-safe. When you are done with
the queue, destroy it with ccircq_destroy().
 
fork(2) and this queue can be combined in two supported ways: Call
fork(2) before you create the queue, or create it and then call fork(2)
followed at once by exec(3). A program that keeps running with no
exec(3) after the fork while a queue from before the fork is live is
not supported. As a defense in depth beyond that rule, the child never
inherits a lock that another thread held, in the locked state, at the
instant of the fork. The queue owns no thread of its own either, so a
queue that a child inherits this way stays fully usable.

ccircq_create_mp(3), ccircq_destroy(3)