htslib.thread_pool

@file htslib/thread_pool.h Thread pool for multi-threading applications.

Members

Functions

hts_tpool_delete_result
void hts_tpool_delete_result(hts_tpool_result* r, int free_data)

Frees a result 'r' and if free_data is true also frees the internal r->data result too.

hts_tpool_destroy
void hts_tpool_destroy(hts_tpool* p)

Destroys a thread pool. The threads are joined into the main thread so they will finish their current work load.

hts_tpool_dispatch
int hts_tpool_dispatch(hts_tpool* p, hts_tpool_process* q, void* function(void* arg) func, void* arg)

@param p Thread pool @param q Process queue @param func Function run by the thread pool @param arg Data for use by func() @return 0 on success -1 on failure

hts_tpool_dispatch2
int hts_tpool_dispatch2(hts_tpool* p, hts_tpool_process* q, void* function(void* arg) func, void* arg, int nonblock)

@param p Thread pool @param q Process queue @param func Function run by the thread pool @param arg Data for use by func() @param nonblock Non-blocking flag (see description) @return 0 on success -1 on failure

hts_tpool_dispatch3
int hts_tpool_dispatch3(hts_tpool* p, hts_tpool_process* q, void* function(void* arg) exec_func, void* arg, void function(void* arg) job_cleanup, void function(void* data) result_cleanup, int nonblock)

@param p Thread pool @param q Process queue @param exec_func Function run by the thread pool @param arg Data for use by func() @param job_cleanup Callback to clean up when discarding jobs @param result_cleanup Callback to clean up when discarding result data @param nonblock Non-blocking flag (see description) @return 0 on success -1 on failure

hts_tpool_init
hts_tpool* hts_tpool_init(int n)

Creates a worker pool with n worker threads.

hts_tpool_kill
void hts_tpool_kill(hts_tpool* p)

Destroys a thread pool without waiting on jobs to complete. Use hts_tpool_kill(p) to quickly exit after a fatal error.

hts_tpool_next_result
hts_tpool_result* hts_tpool_next_result(hts_tpool_process* q)

Pulls the next item off the process result queue. The caller should free it (and any internals as appropriate) after use. This doesn't wait for a result to be present.

hts_tpool_next_result_wait
hts_tpool_result* hts_tpool_next_result_wait(hts_tpool_process* q)

Pulls the next item off the process result queue. The caller should free it (and any internals as appropriate) after use. This will wait for a result to be present if none are currently available.

hts_tpool_process_attach
void hts_tpool_process_attach(hts_tpool* p, hts_tpool_process* q)

Attach and detach a thread process-queue with / from the thread pool scheduler.

hts_tpool_process_destroy
void hts_tpool_process_destroy(hts_tpool_process* q)

Deallocates memory for a thread process-queue. Must be called before the thread pool is destroyed.

hts_tpool_process_detach
void hts_tpool_process_detach(hts_tpool* p, hts_tpool_process* q)

Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

hts_tpool_process_empty
int hts_tpool_process_empty(hts_tpool_process* q)

Returns true if there are no items in the process results queue and also none still pending.

hts_tpool_process_flush
int hts_tpool_process_flush(hts_tpool_process* q)

Flushes the process-queue, but doesn't exit. This simply drains the queue and ensures all worker threads have finished their current tasks associated with this process.

hts_tpool_process_init
hts_tpool_process* hts_tpool_process_init(hts_tpool* p, int qsize, int in_only)

Initialises a thread process-queue.

hts_tpool_process_len
int hts_tpool_process_len(hts_tpool_process* q)

Returns the number of completed jobs in the process results queue.

hts_tpool_process_qsize
int hts_tpool_process_qsize(hts_tpool_process* q)

Returns the process queue size

hts_tpool_process_ref_decr
void hts_tpool_process_ref_decr(hts_tpool_process* q)

Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

hts_tpool_process_ref_incr
void hts_tpool_process_ref_incr(hts_tpool_process* q)

Increment and decrement the reference count in a process-queue. If the queue is being driven from two external (non thread-pool) threads, eg "main" and a "reader", this permits each end to decrement its use of the process-queue independently.

hts_tpool_process_reset
int hts_tpool_process_reset(hts_tpool_process* q, int free_results)

Resets a process to the initial state.

hts_tpool_process_shutdown
void hts_tpool_process_shutdown(hts_tpool_process* q)

Shutdown a process.

hts_tpool_process_sz
int hts_tpool_process_sz(hts_tpool_process* q)

Returns the number of completed jobs in the process results queue plus the number running and queued up to run.

hts_tpool_result_data
void* hts_tpool_result_data(hts_tpool_result* r)

Returns the data portion of a hts_tpool_result, corresponding to the actual "result" itself.

hts_tpool_size
int hts_tpool_size(hts_tpool* p)

Returns the number of requested threads for a pool.

hts_tpool_wake_dispatch
void hts_tpool_wake_dispatch(hts_tpool_process* q)

Wakes up a single thread stuck in dispatch and make it return with errno EAGAIN.

Structs

hts_tpool
struct hts_tpool

The single pool structure itself.

hts_tpool_process
struct hts_tpool_process

An hts_tpool_process implements a queue of input jobs to process and a queue of resulting output post-processing. Internally it consists of two buffered queues, analogous to the pipes in a unix pipeline: ...input | process | output...

hts_tpool_result
struct hts_tpool_result

An output, after job has executed.

Meta