C Collections

cthreadpool · Section 3

cthrpool_timed_submit_future

cthrpool_timed_submit_future - submit a future task with a relative timeout

C Collections (libccollections, -lccollections)

#include <ccollections/cthreadpool.h>
 
ccol_retval cthrpool_timed_submit_future(cthrpool pool,
                                           void *(*fn)(void *),
                                           void *arg,
                                           uint64_t timeout_us,
                                           cthrpool_future **out);

Allocates a future and submits it to the pool, and on a bounded queue
waits at most timeout_us microseconds for a free slot, counted from
the call. The timeout is turned into an absolute deadline on
CLOCK_MONOTONIC, so a change to the system's wall clock (by an
administrator, by NTP, or when a virtual machine resumes) makes the
wait neither longer nor shorter.
 
A timeout_us of 0 makes the call the same as cthrpool_try_submit_future,
which doesn't wait.
 
A timeout too large to form a deadline, such as UINT64_MAX, waits as
long as the queue stays full: The deadline saturates at the latest
time that can be represented and never wraps into the past.
 
A call from a task running on this same pool, or from the on_complete
callback of that task, never waits while a bounded queue is at
capacity, because only the workers of this pool can free a slot and
the caller is one of them. It returns ccol_container_full at once,
whatever timeout_us says.
 
On success *out is set to a new cthrpool_future handle with a reference
count of 2: The caller holds one reference, and the queued task holds
the other. The caller must call cthrpool_future_free exactly once when
it is done.

pool        Thread pool handle
fn          Task function returning void* (must not be NULL)
arg         The library gives it to fn (may be NULL)
timeout_us  Longest time to wait, in microseconds (0 means do not wait)
out         Receives the future handle on success. The function sets it
            to NULL on a failure (must not be NULL)

ccol_success            - task enqueued; *out set to the future handle.
ccol_invalid_args       - pool is CTHRPOOL_NULL or a stale/already-
                          destroyed handle, or fn or out is NULL.
ccol_not_enough_memory  - future or task allocation failed.
ccol_not_permitted      - pool is shutting down.
ccol_container_full     - the queue is full and timeout_us is 0, or
                          the caller is a task of this pool (see
                          above).
ccol_timed_out          - timeout elapsed before a slot became free.
ccol_unexpected_failure - clock_gettime or pthread_cond_timedwait
                          returned an unexpected error.

cthrpool_submit_future(3), cthrpool_try_submit_future(3), cthrpool_future_get(3), cthrpool_future_free(3)