/************************************************************************
 * AUTHOR: NiuJiuRu
 * FILENAME: swthrdpool.h
 * CONTENT: 线程池
 * NOTE:
 * HISTORY:
 * 1, [2010-09-20] created by NiuJiuRu
 * 2, [2018-03-23] add "sw_thrdpool_create2()" function and redefine
 *                 "sw_thrdpool_create()" function
 ***********************************************************************/
#ifndef __SWTHRDPOOL_H__
#define __SWTHRDPOOL_H__

#include "swthrd.h"

#ifdef __cplusplus
extern "C"
{
#endif

/* 创建线程池 */
void *sw_thrdpool_create2(int max, int priority, int stack_size);

#define sw_thrdpool_create(max) \
  sw_thrdpool_create2(max, THREAD_DEFAULT_PRIORITY, THREAD_DEFAULT_STACK_SIZE)

/* 销毁线程池, 超时前尝试安全的销毁, 超时后则强制销毁 */
void sw_thrdpool_destroy(void *hPool, int timeout);

/* 从线程池中分配一个线程, 成功后得到的线程默认处于暂停状态 */
void *sw_thrdpool_alloc(void *hPool, PThrdProc proc, unsigned long wParam, unsigned long lParam, int timeout);

/* 从线程池中释放一个线程, 超时前尝试安全的关闭线程, 超时后则强制关闭线程 */
void sw_thrdpool_free(void *hPool, void *hThrd, int timeout);

/* 获取线程池当前的线程分配情况 */
void sw_thrdpool_get_status(void *hPool, int *max_num, int *alloc_num, int *idle_num, int *sick_num, int *killed_num);

/* 打印线程池当前的线程分配情况 */
void sw_thrdpool_printf(void *hPool);

#ifdef __cplusplus
}
#endif

#endif /* __SWTHRDPOOL_H__ */
