|
static struct m0_parallel_queue_link * | parallel_queue_get (struct m0_parallel_queue *queue) |
|
static void | parallel_queue_add (struct m0_parallel_queue *queue, struct m0_parallel_queue_link *link) |
|
static void | parallel_queue_init (struct m0_parallel_queue *queue) |
|
static void | parallel_queue_fini (struct m0_parallel_queue *queue) |
|
static void | parallel_queue_link_init (struct m0_parallel_queue_link *l) |
|
static void | pool_thread (struct m0_parallel_pool *pool) |
|
static void | pool_threads_fini (struct m0_parallel_pool *pool, bool join) |
|
static void | parallel_pool_fini (struct m0_parallel_pool *pool, bool join) |
|
static int | pool_threads_init (struct m0_parallel_pool *pool, int thread_nr, int qlink_nr) |
|
M0_INTERNAL int | m0_parallel_pool_init (struct m0_parallel_pool *pool, int thread_nr, int qlinks_nr) |
|
M0_INTERNAL void | m0_parallel_pool_fini (struct m0_parallel_pool *pool) |
|
M0_INTERNAL void | m0_parallel_pool_start (struct m0_parallel_pool *pool, int(*process)(void *item)) |
|
M0_INTERNAL int | m0_parallel_pool_wait (struct m0_parallel_pool *pool) |
|
M0_INTERNAL void | m0_parallel_pool_terminate_wait (struct m0_parallel_pool *pool) |
|
M0_INTERNAL int | m0_parallel_pool_job_add (struct m0_parallel_pool *pool, void *item) |
|
M0_INTERNAL int | m0_parallel_pool_rc_next (struct m0_parallel_pool *pool, void **job, int *rc) |
|
M0_INTERNAL void | m0_parallel_pool_start (struct m0_parallel_pool *pool, int(*process)(void *job)) |
|
Simple parallel pool abstraction gives user controlled number of threads allowing him to add its own jobs for processing. User operates pool by adding its set of jobs and processing function which is called on every such job.
Pools have the following life-cycle:
// user creates pool, number of threads and ‘jobs processed at once’ are set: struct m0_parallel_pool p = {}; m0_parallel_pool_init(&p, THREADS_NR, JOBS_AT_ONCE_NR);
// something can be done even repeatingly forall(subjobs:jobs) { // then user has to add jobs to process with given on the next step // function forall (job:subjobs) m0_parallel_pool_job_add(&p, job);
// then pool starts job processing, ‘int job_process(void* job)’ is being // applied to every given job m0_parallel_pool_start(&p, &job_process);
// user may wait job processing end; m0_parallel_pool_wait() // returns -EINTR if any ‘int job_process(void* job)’ returned error. rc = m0_parallel_pool_wait(&p); // handle ‘rc’ if needed. // ... }
// in some cases ‘jobs’ are linked into lists, therefore M0_PARALLEL_FOR() // can be used to perform the same as in loop above; // assume ‘ljobs’ is a typed list with corresponding prefix ‘m0_ljobs’:
// equivalent to ‘forall(subjobs:jobs)’ for typed lists rc = M0_PARALLEL_FOR(m0_ljobs, &p, &ljobs, &job_process);
// after all, pool has to be terminated and then finalized; terminate waits // until all threads in pool are joined. m0_parallel_pool_terminate_wait(&p); m0_parallel_pool_fini(&p);
◆ M0_PARALLEL_FOR
Value:({ \
m0_parallel_pool_start(
pool, process); \
break; \
} \
m0_parallel_pool_start(
pool, process); \
} \
})
M0_INTERNAL int m0_parallel_pool_job_add(struct m0_parallel_pool *pool, void *item)
static struct m0_list list
M0_INTERNAL int m0_parallel_pool_wait(struct m0_parallel_pool *pool)
static struct m0_pool pool
Definition at line 116 of file thread_pool.h.
◆ M0_TRACE_SUBSYSTEM
#define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_LIB |
◆ m0_parallel_pool_state
Enumerator |
---|
PPS_IDLE | |
PPS_BUSY | |
PPS_TERMINATING | |
PPS_TERMINATED | |
Definition at line 37 of file thread_pool.c.
◆ m0_parallel_pool_fini()
◆ m0_parallel_pool_init()
M0_INTERNAL int m0_parallel_pool_init |
( |
struct m0_parallel_pool * |
pool, |
|
|
int |
thread_nr, |
|
|
int |
qlinks_nr |
|
) |
| |
◆ m0_parallel_pool_job_add()
M0_INTERNAL int m0_parallel_pool_job_add |
( |
struct m0_parallel_pool * |
pool, |
|
|
void * |
item |
|
) |
| |
◆ m0_parallel_pool_rc_next()
M0_INTERNAL int m0_parallel_pool_rc_next |
( |
struct m0_parallel_pool * |
pool, |
|
|
void ** |
job, |
|
|
int * |
rc |
|
) |
| |
◆ m0_parallel_pool_start() [1/2]
M0_INTERNAL void m0_parallel_pool_start |
( |
struct m0_parallel_pool * |
pool, |
|
|
int(*)(void *job) |
process |
|
) |
| |
◆ m0_parallel_pool_start() [2/2]
M0_INTERNAL void m0_parallel_pool_start |
( |
struct m0_parallel_pool * |
pool, |
|
|
int(*)(void *item) |
process |
|
) |
| |
◆ m0_parallel_pool_terminate_wait()
M0_INTERNAL void m0_parallel_pool_terminate_wait |
( |
struct m0_parallel_pool * |
pool | ) |
|
◆ m0_parallel_pool_wait()
◆ parallel_pool_fini()
◆ parallel_queue_add()
◆ parallel_queue_fini()
◆ parallel_queue_get()
◆ parallel_queue_init()
◆ parallel_queue_link_init()
◆ pool_thread()
◆ pool_threads_fini()
◆ pool_threads_init()
static int pool_threads_init |
( |
struct m0_parallel_pool * |
pool, |
|
|
int |
thread_nr, |
|
|
int |
qlink_nr |
|
) |
| |
|
static |