rtp.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __RTP_H__
  2. #define __RTP_H__
  3. #include "rtp_def.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #define RTP_NAME_LEN 16
  8. #define RTP_PRIORITY 10
  9. typedef void (*task_handle)(void *argv);
  10. typedef struct rtp_task_ {
  11. task_handle handle;
  12. void *argv;
  13. struct rtp_task_ *next;
  14. }rtp_task;
  15. typedef struct {
  16. struct rtp_task_attr attr;
  17. rtp_task_id *thread_id;
  18. }rtp_thread_info;
  19. typedef struct {
  20. rtp_mutex_id queue_lock;
  21. rtp_sem_id queue_ready;
  22. rtp_thread_info *threads;
  23. rtp_task *task_queue;
  24. uint8_t thread_num;
  25. uint8_t wait_task_num;
  26. }rtp;
  27. /**
  28. * Create thread pool
  29. *
  30. * @param pool thread pool handle
  31. * @param name thread name
  32. * @param stackSize thread stack size
  33. * @param threadNum Number of threads in thread pool
  34. * @return create thread pool result.
  35. * RTP_EOK: init success
  36. * RTP_ERROR: init failed
  37. */
  38. rtp_err_t rtp_create(rtp *pool, const char *name,
  39. uint32_t stackSize, uint8_t threadNum);
  40. /**
  41. * Adding tasks to the thread pool
  42. *
  43. * @param pool thread pool handle
  44. * @param handl task handler
  45. * @param argv task parameter
  46. * @return add task result.
  47. * RTP_EOK: init success
  48. * RTP_ERROR: init failed
  49. */
  50. rtp_err_t rtp_add_task(rtp *pool, task_handle handle, void *argv);
  51. /**
  52. * Suspend all threads in the thread pool
  53. *
  54. * @param pool thread pool handle
  55. */
  56. void rtp_suspend(rtp *pool);
  57. /**
  58. * Resume all threads in the thread pool
  59. *
  60. * @param pool thread pool handle
  61. */
  62. void rtp_resume(rtp *pool);
  63. /**
  64. * Get the number of tasks in the thread pool
  65. *
  66. * @param pool thread pool handle
  67. * @return task number.
  68. */
  69. int rtp_wait_task_num(rtp *pool);
  70. /**
  71. * Destroy thread pool
  72. *
  73. * @param pool thread pool handle
  74. * @return destroy thread pool result.
  75. * RTP_EOK: init success
  76. * RTP_ERROR: init failed
  77. */
  78. rtp_err_t rtp_destroy(rtp *pool);
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif