Motr  M0
Thread pool

Data Structures

struct  m0_parallel_queue_link
 
struct  m0_parallel_queue
 
struct  m0_parallel_pool
 

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_LIB
 
#define M0_PARALLEL_FOR(name, pool, list, process)
 

Enumerations

enum  m0_parallel_pool_state { PPS_IDLE = 1, PPS_BUSY, PPS_TERMINATING, PPS_TERMINATED }
 

Functions

static struct m0_parallel_queue_linkparallel_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))
 

Detailed Description

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);

Macro Definition Documentation

◆ M0_PARALLEL_FOR

#define M0_PARALLEL_FOR (   name,
  pool,
  list,
  process 
)
Value:
({ \
int rc = -EINVAL; \
typeof (name ## _tlist_head(NULL)) obj; \
m0_tl_for(name, list, obj) { \
if (rc == -EFBIG) { \
m0_parallel_pool_start(pool, process); \
if (rc != 0) \
break; \
M0_POST(rc == 0); \
} \
if (rc == 0) { \
m0_parallel_pool_start(pool, process); \
} \
(rc); \
})
M0_INTERNAL int m0_parallel_pool_job_add(struct m0_parallel_pool *pool, void *item)
Definition: thread_pool.c:264
static struct m0_list list
Definition: list.c:144
#define NULL
Definition: misc.h:38
M0_INTERNAL int m0_parallel_pool_wait(struct m0_parallel_pool *pool)
Definition: thread_pool.c:229
static struct foo * obj
Definition: tlist.c:302
#define m0_tl_endfor
Definition: tlist.h:700
const char * name
Definition: trace.c:110
static struct m0_pool pool
Definition: iter_ut.c:58
int32_t rc
Definition: trigger_fop.h:47

Definition at line 116 of file thread_pool.h.

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_LIB

Definition at line 30 of file thread_pool.c.

Enumeration Type Documentation

◆ m0_parallel_pool_state

Enumerator
PPS_IDLE 
PPS_BUSY 
PPS_TERMINATING 
PPS_TERMINATED 

Definition at line 37 of file thread_pool.c.

Function Documentation

◆ m0_parallel_pool_fini()

M0_INTERNAL void m0_parallel_pool_fini ( struct m0_parallel_pool pool)

Definition at line 204 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_parallel_pool_init()

M0_INTERNAL int m0_parallel_pool_init ( struct m0_parallel_pool pool,
int  thread_nr,
int  qlinks_nr 
)

Definition at line 189 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_parallel_pool_job_add()

M0_INTERNAL int m0_parallel_pool_job_add ( struct m0_parallel_pool pool,
void *  item 
)

Definition at line 264 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_parallel_pool_rc_next()

M0_INTERNAL int m0_parallel_pool_rc_next ( struct m0_parallel_pool pool,
void **  job,
int *  rc 
)

Definition at line 281 of file thread_pool.c.

Here is the caller graph for this function:

◆ 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 
)

Definition at line 210 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_parallel_pool_terminate_wait()

M0_INTERNAL void m0_parallel_pool_terminate_wait ( struct m0_parallel_pool pool)

Definition at line 247 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_parallel_pool_wait()

M0_INTERNAL int m0_parallel_pool_wait ( struct m0_parallel_pool pool)

Definition at line 229 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parallel_pool_fini()

static void parallel_pool_fini ( struct m0_parallel_pool pool,
bool  join 
)
static

Definition at line 142 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parallel_queue_add()

static void parallel_queue_add ( struct m0_parallel_queue queue,
struct m0_parallel_queue_link link 
)
static

Definition at line 70 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parallel_queue_fini()

static void parallel_queue_fini ( struct m0_parallel_queue queue)
static

Definition at line 84 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parallel_queue_get()

static struct m0_parallel_queue_link* parallel_queue_get ( struct m0_parallel_queue queue)
static

Definition at line 59 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parallel_queue_init()

static void parallel_queue_init ( struct m0_parallel_queue queue)
static

Definition at line 78 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parallel_queue_link_init()

static void parallel_queue_link_init ( struct m0_parallel_queue_link l)
static

Definition at line 90 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pool_thread()

static void pool_thread ( struct m0_parallel_pool pool)
static

Definition at line 99 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pool_threads_fini()

static void pool_threads_fini ( struct m0_parallel_pool pool,
bool  join 
)
static

Definition at line 126 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pool_threads_init()

static int pool_threads_init ( struct m0_parallel_pool pool,
int  thread_nr,
int  qlink_nr 
)
static

Definition at line 149 of file thread_pool.c.

Here is the call graph for this function:
Here is the caller graph for this function: