cthreadcomm · Section 3
ceventloop_create
NAME
ceventloop_create - create a ceventloop with default memory management
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h>
ceventloop_create(max_events_per_wait, num_lock_stripes,
num_reactor_threads, err_str);
DESCRIPTION
The same as ceventloop_create_mp() with mmgmt_procs = NULL, which selects the standard malloc and free.
PARAMETERS
max_events_per_wait Size of the epoll_wait batch buffer of the
poller thread, from 1 to INT_MAX inclusive, and
small enough that max_events_per_wait *
sizeof(struct epoll_event) fits in a size_t. It
limits how many ready events one epoll_wait call
drains, not how many registrations the loop can
hold.
num_lock_stripes Number of independent lock stripes for the
registry of fds and entries, at least 1. With 1
there is a single shared lock. A larger value
lowers the contention between
ceventloop_add, ceventloop_remove and
ceventloop_modify, which grows when threads
work on many different fds and registrations at
the same time.
num_reactor_threads Total number of OS threads the loop uses for
polling and dispatching, at least 1. Whatever
the value, exactly one dedicated thread calls
epoll_wait on the shared epoll instance. With 1
that thread also dispatches every callback
inline; a larger value adds
(num_reactor_threads - 1) separate dispatch
worker threads.
err_str Optional pointer that gets an error string on a
failure. Pass NULL to ignore it.
RETURN VALUE
A new ceventloop handle on success, or CEVENTLOOP_NULL when an argument is invalid, an allocation failed, epoll_create1, eventfd or pthread_create failed, the process had no thread-specific key left for the dispatch of a loop, the library's process-exit destructors have run and the last loop is gone, or no handle slot could be allocated. ceventloop_create_mp(3) has the details.
NOTES
All of the loop's background reactor threads are already running when the call returns. When you are done with the loop, destroy it with ceventloop_destroy().
SEE ALSO
ceventloop_create_mp(3), ceventloop_destroy(3), ceventloop_add(3)