libcrystfel 0.11.1
Loading...
Searching...
No Matches
Typedefs | Functions
thread-pool.h File Reference

Typedefs

typedef void *(* TPGetTaskFunc) (void *qargs)
 
typedef void(* TPWorkFunc) (void *work, int cookie)
 
typedef void(* TPFinalFunc) (void *qargs, void *work)
 

Functions

signed int get_status_label (void)
 
int run_threads (int n_threads, TPWorkFunc work, TPGetTaskFunc get_task, TPFinalFunc final, void *queue_args, int max, int cpu_num, int cpu_groupsize, int cpu_offset)
 

Detailed Description

Thread pool.

Typedef Documentation

◆ TPFinalFunc

typedef void(* TPFinalFunc) (void *qargs, void *work)
Parameters
qargsThe queue_args pointer which was given to run_threads.
workThe pointer which was returned by your get_task function.

This function is called, non-reentrantly, after each work item has been completed. A typical use might be to update some counters inside qargs according to fields withing work which were filled by your 'work' function.

◆ TPGetTaskFunc

typedef void *(* TPGetTaskFunc) (void *qargs)

qargs: The queue_args pointer which was given to run_threads().

Returns
a pointer which will be passed to the worker function.

This function is called, non-reentrantly, to get a new work item to give to your work function. The stuff you need to generate the new work item should have been stored in qargs which was passed to run_threads.

◆ TPWorkFunc

typedef void(* TPWorkFunc) (void *work, int cookie)
Parameters
workThe queue_args pointer which was given to run_threads.
cookieA small integral number which is guaranteed to be unique among all currently running threads.

This function is called, reentrantly, for each work item.

Function Documentation

◆ run_threads()

int run_threads ( int n_threads,
TPWorkFunc work,
TPGetTaskFunc get_task,
TPFinalFunc final,
void * queue_args,
int max,
int cpu_num,
int cpu_groupsize,
int cpu_offset )
extern
Parameters
n_threadsThe number of threads to run in parallel
workThe function to be called to do the work
get_taskThe function which will determine the next unassigned task
finalThe function which will be called to clean up after a task
queue_argsA pointer to any data required to determine the next task
maxStop calling get_task after starting this number of jobs
cpu_numIgnored
cpu_groupsizeIgnored
cpu_offsetIgnored

get_task will be called every time a worker is idle. It returns either NULL, indicating that no further work is available, or a pointer which will be passed to work.

final will be called once per image, and will be given both queue_args and the last task pointer.

get_task and final will be called only under lock, and so do NOT need to be re-entrant or otherwise thread safe. 'work', of course, needs to be thread safe.

Work will stop after max tasks have been processed whether get_task returned NULL or not. If max is zero, all tasks will be processed.

Returns
The number of tasks completed.