rr-workpool

Name

rr-workpool -- 

Synopsis



struct      RRWorkPool;
struct      RRWorkPoolClass;
#define     RRWPGROUP                       (x)
typedef     RRWPGroup;
RRWorkPool* rr_work_pool_new                (gint max_threads);
void        rr_work_pool_free               (RRWorkPool *pool);
void        rr_work_pool_push               (RRWorkPool *pool,
                                             RRWPGroup gid,
                                             GFunc func,
                                             gpointer data,
                                             gpointer user_data);
void        rr_work_pool_join               (RRWorkPool *pool,
                                             RRWPGroup gid);

Description

Details

struct RRWorkPool

struct RRWorkPool {
	gint max_threads;
	gint num_threads;
	GSList *work;
	GSList *active;
	GMutex *mutex;
	GCond  *add_cond;
	GCond  *remove_cond;
	gboolean shutdown;
};


struct RRWorkPoolClass

struct RRWorkPoolClass;


RRWPGROUP()

#define RRWPGROUP(x) ((RRWPGroup)x)

x :


RRWPGroup

typedef guint RRWPGroup;


rr_work_pool_new ()

RRWorkPool* rr_work_pool_new                (gint max_threads);

Create a new work pool. The RRWorkPool works like an ordinary thread pool with the exception that each "work item" is assigned a gid (group id). But the work pool guarantees that two items with the same gid value cant be executed in parallel.

max_threads :

The maximum number of threads this pool should use.

Returns :

a newly allocated RRWorkPool.


rr_work_pool_free ()

void        rr_work_pool_free               (RRWorkPool *pool);

Waits until all work items have been executed then all resourced used by the work pool are returned to the operating system.

pool :

A RRWorkPool.


rr_work_pool_push ()

void        rr_work_pool_push               (RRWorkPool *pool,
                                             RRWPGroup gid,
                                             GFunc func,
                                             gpointer data,
                                             gpointer user_data);

Inserts func to the list of task to be executed by the pool. The work pool guarantees that two or more tasks with the same gid will never be executed in parallel.

pool :

a RRWorkPool

gid :

a thread group id.

func :

a function to execute by one thread in the work pool.

data :

first argument to func

user_data :

second argument to func


rr_work_pool_join ()

void        rr_work_pool_join               (RRWorkPool *pool,
                                             RRWPGroup gid);

blocks until all tasks of the given gid are executed.

pool :

a RRWork pool.

gid :

a thread group id