summaryrefslogtreecommitdiff
path: root/src/threadpool.h
blob: bc3ce06cbc12a815cd39ac00affdae3884cfb6bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef __VXGG_REWRITE___THREADPOOL_H___13601325413136___
#define __VXGG_REWRITE___THREADPOOL_H___13601325413136___

#include <threads.h>

typedef int (*task_callback)(void*);
typedef struct task task;
typedef struct cq cqueue;
typedef struct tp threadpool;

task * task_init(task_callback cb, void *arg);
void task_free(task *ts);

cqueue * cqueue_init(int mtx_type);
void cqueue_free(cqueue *cq);
int cqueue_append(cqueue * const cq, task *tsk);
int cqueue_prepend(cqueue * const cq, task *tsk);
int cqueue_insert(cqueue * const cq, task *tsk, int index);
int cqueue_size(cqueue const * const cq);
int cqueue_isempty(cqueue const * const cq);
int cqueue_trypop(cqueue * const cq, task **ret);
int cqueue_waitpop(cqueue * const cq, task **ret);
int cqueue_cancel(cqueue * const cq);

threadpool * threadpool_init(int threads);
void threadpool_free(threadpool *tp);
int threadpool_addtask(threadpool * const tp, task * const task);
int threadpool_join(const threadpool * const tp);

typedef struct mtxp mtxpair;
mtxpair * mtxpair_init(void * const data, int type);
void mtxpair_free(mtxpair *mp);
int mtxpair_setdata(mtxpair * const mp, void * const data);
int thrd_createwmx(thrd_t * const thr, thrd_start_t func, mtxpair * const mtxd);

#endif