-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathppool.h
More file actions
45 lines (33 loc) · 878 Bytes
/
ppool.h
File metadata and controls
45 lines (33 loc) · 878 Bytes
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
37
38
39
40
41
42
43
44
45
#ifndef _PPOOL_H
#define _PPOOL_H
#include <pthread.h>
#include "ppool_queue.h"
typedef char pbool;
#define PTRUE 1
#define PFALSE 0
pthread_mutex_t PPOOL_LOCK;
#define ppool_entry() pthread_mutex_lock(&PPOOL_LOCK)
#define ppool_leave() pthread_mutex_unlock(&PPOOL_LOCK)
typedef struct
{
int pool_max_num; //线程池最大线程数量
int rel_num; //线程池中实例线程数
pool_w *head; //线程头
pthread_t *id; //线程id
pthread_mutex_t ppool_lock;
pthread_cond_t ppool_cond;
}pool_t;
//任务数据结构
typedef struct
{
int priority; //优先级
ppool_work task; //任务
void *arg; //参数
}pool_task;
//初始化一个线程池
pool_t *ppool_init(int pool_max_num);
//向线程池中添加一个任务
pbool ppool_add(pool_t *pool,pool_task *task);
//销毁一个线程池
void ppool_destroy(pool_t *pool);
#endif