swthrdpool.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /************************************************************************
  2. * AUTHOR: NiuJiuRu
  3. * FILENAME: swthrdpool.h
  4. * CONTENT: 线程池
  5. * NOTE:
  6. * HISTORY:
  7. * 1, [2010-09-20] created by NiuJiuRu
  8. * 2, [2018-03-23] add "sw_thrdpool_create2()" function and redefine
  9. * "sw_thrdpool_create()" function
  10. ***********************************************************************/
  11. #ifndef __SWTHRDPOOL_H__
  12. #define __SWTHRDPOOL_H__
  13. #include "swthrd.h"
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif
  18. /* 创建线程池 */
  19. void *sw_thrdpool_create2(int max, int priority, int stack_size);
  20. #define sw_thrdpool_create(max) \
  21. sw_thrdpool_create2(max, THREAD_DEFAULT_PRIORITY, THREAD_DEFAULT_STACK_SIZE)
  22. /* 销毁线程池, 超时前尝试安全的销毁, 超时后则强制销毁 */
  23. void sw_thrdpool_destroy(void *hPool, int timeout);
  24. /* 从线程池中分配一个线程, 成功后得到的线程默认处于暂停状态 */
  25. void *sw_thrdpool_alloc(void *hPool, PThrdProc proc, unsigned long wParam, unsigned long lParam, int timeout);
  26. /* 从线程池中释放一个线程, 超时前尝试安全的关闭线程, 超时后则强制关闭线程 */
  27. void sw_thrdpool_free(void *hPool, void *hThrd, int timeout);
  28. /* 获取线程池当前的线程分配情况 */
  29. void sw_thrdpool_get_status(void *hPool, int *max_num, int *alloc_num, int *idle_num, int *sick_num, int *killed_num);
  30. /* 打印线程池当前的线程分配情况 */
  31. void sw_thrdpool_printf(void *hPool);
  32. #ifdef __cplusplus
  33. }
  34. #endif
  35. #endif /* __SWTHRDPOOL_H__ */