cthreadcomm · Section 3
cdynmq_create_mp
NAME
cdynmq_create_mp - create a dynamic queue with no size limit and with custom memory management
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h>
cdynmq *cdynmq_create_mp(
ccol_memmgmt_procs *mmgmt_procs, char **err_str);
DESCRIPTION
Creates a queue with no size limit, kept in a doubly-linked list. A send never waits for free space. It fails instead, when an allocation fails, when the queue already holds ccol_max_elem_count messages, or when sends were turned off with cdynmq_disable_sending(3). A new queue starts with sends on. Every allocation, at creation and for each list node that a later send adds, goes through mmgmt_procs. The queue keeps its own copy of the procedures and frees itself through them, so the caller's ccol_memmgmt_procs doesn't have to outlive this call. NULL selects the default malloc and free, which is what the cdynmq_create() macro passes.
PARAMETERS
mmgmt_procs Custom memory management procedures, or NULL to use the
default malloc and free. If the value is not NULL, all of
malloc, calloc, realloc and free must be set.
err_str Optional pointer that gets an error string on failure. Pass
NULL to ignore it.
RETURN VALUE
On success, a pointer to the new dynamic queue, and *err_str is set to NULL when err_str is not NULL. On failure, NULL, and *err_str describes the reason when err_str is not NULL. The call fails when mmgmt_procs is malformed because it sets some but not all of malloc, calloc, realloc and free, when an allocation fails, when the queue's mutex or its condition variable cannot be initialized, and, in a build with fork-safety protection compiled in, when the queue's mutex cannot be registered with the fork-safety registry. That registration also fails once the library's process-exit destructors have run and the last queue is gone, for example in an application destructor that runs after them. None of these failures leaves anything allocated.
NOTES
All operations on this queue are thread-safe. When you are done with the queue, destroy it with cdynmq_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.
SEE ALSO
cdynmq_create(3), cdynmq_destroy(3), cdynmq_send(3), cdynmq_recv(3)