发生

来源:互联网 发布:二元期权编程自动交易 编辑:程序博客网 时间:2024/04/29 02:28

/*************************************************************************
> File Name: tpool.h
> Author: 
> Mail: 
> Created Time: 2015年04月01日 星期三 17时34分00秒
************************************************************************/

#ifndef THREAD_POOL_H__
#define THREAD_POOL_H__

#include <pthread.h>

/* 要执行的任务链表 */
typedef struct tpool_work {
void* (*routine)(int); /* 任务函数 */
int arg; /* 传入任务函数的参数 */
struct tpool_work *next; 
}tpool_work_t;

typedef struct tpool {
int shutdown; /* 线程池是否销毁 */
int max_thr_num; /* 最大线程数 */
pthread_t *thr_id; /* 线程ID数组 */
tpool_work_t *queue_head; /* 线程链表 */
pthread_mutex_t queue_lock; 
pthread_cond_t queue_ready; 
}tpool_t;

/*
* @brief 创建线程池 
* @param max_thr_num 最大线程数
* @return 0: 成功 其他: 失败 
*/
int
tpool_create(int max_thr_num);

/*
* @brief 销毁线程池 
*/
void
tpool_destroy();

/*
* @brief 向线程池中添加任务
* @param routine 任务函数指针
* @param arg 任务函数参数
* @return 0: 成功 其他:失败 
*/
int
tpool_add_work(void*(*routine)(int), int arg);

#endif

/*************************************************************************> File Name: tpool.h> Author: > Mail: > Created Time: 2015年04月01日 星期三 17时34分00秒************************************************************************/#ifndef THREAD_POOL_H__#define THREAD_POOL_H__#include <pthread.h>/* 要执行的任务链表 */typedef struct tpool_work {void* (*routine)(int); /* 任务函数 */int arg; /* 传入任务函数的参数 */struct tpool_work *next; }tpool_work_t;typedef struct tpool {int shutdown; /* 线程池是否销毁 */int max_thr_num; /* 最大线程数 */pthread_t *thr_id; /* 线程ID数组 */tpool_work_t *queue_head; /* 线程链表 */pthread_mutex_t queue_lock; pthread_cond_t queue_ready; }tpool_t;/** @brief 创建线程池 * @param max_thr_num 最大线程数* @return 0: 成功 其他: 失败 */inttpool_create(int max_thr_num);/** @brief 销毁线程池 */voidtpool_destroy();/** @brief 向线程池中添加任务* @param routine 任务函数指针* @param arg 任务函数参数* @return 0: 成功 其他:失败 */inttpool_add_work(void*(*routine)(int), int arg);#endif

/*************************************************************************> File Name: tpool.h> Author: > Mail: > Created Time: 2015年04月01日 星期三 17时34分00秒************************************************************************/#ifndef THREAD_POOL_H__#define THREAD_POOL_H__#include <pthread.h>/* 要执行的任务链表 */typedef struct tpool_work {void* (*routine)(int); /* 任务函数 */int arg; /* 传入任务函数的参数 */struct tpool_work *next; }tpool_work_t;typedef struct tpool {int shutdown; /* 线程池是否销毁 */int max_thr_num; /* 最大线程数 */pthread_t *thr_id; /* 线程ID数组 */tpool_work_t *queue_head; /* 线程链表 */pthread_mutex_t queue_lock; pthread_cond_t queue_ready; }tpool_t;/** @brief 创建线程池 * @param max_thr_num 最大线程数* @return 0: 成功 其他: 失败 */inttpool_create(int max_thr_num);/** @brief 销毁线程池 */voidtpool_destroy();/** @brief 向线程池中添加任务* @param routine 任务函数指针* @param arg 任务函数参数* @return 0: 成功 其他:失败 */inttpool_add_work(void*(*routine)(int), int arg);#endif

0 0
原创粉丝点击