加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
thread_pool.h 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
jin 提交于 2024-02-19 18:04 . test opencv decode video
#ifndef _THREAD_POOL_H_
#define _THREAD_POOL_H_
#include <pthread.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define TASK_QUEUE_SIZE 32
#define TASK_NUMBER 2
// task struct
typedef struct _task
{
void (*function)(void *argv);
void *arg;
} task_t;
// thread pool struct
typedef struct _threadpool
{
// task queue
task_t *tasks;
int task_capacity;
int task_size;
int task_head;
int task_tail;
pthread_t manager_id;
pthread_t *worker_ids;
int min_num;
int max_num;
int busy_num;
int live_num;
int exit_num;
pthread_mutex_t mutex_pool;
pthread_mutex_t mutex_busy;
pthread_cond_t not_full;
pthread_cond_t not_empty;
int shutdown;
} threadpool;
// create threadpool
threadpool *threadpool_create(int min, int max);
// destroy threadpool
int threadpool_destroy(threadpool *pool);
// add task into threadpool
void threadpool_add(threadpool *pool, task_t task);
// get busy task num
int threadpool_busy_num(threadpool *pool);
// get live task num
int threadpool_live_num(threadpool *pool);
// manager
void *manager(void *arg);
// workers
void *worker(void *arg);
// one thread exit
void thread_exit(threadpool *pool);
#ifdef __cplusplus
}
#endif // !__cplusplus
#endif // !_THREAD_POOL_H_
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化