|
|
2 lat temu | |
|---|---|---|
| adapter | 2 lat temu | |
| include | 2 lat temu | |
| pic | 2 lat temu | |
| src | 2 lat temu | |
| README.md | 2 lat temu | |
| SConscript | 2 lat temu | |
| main.c | 2 lat temu |
RTP组件,又称线程池组件。是作者编写一个多线程管理组件,特点:
tp的提供的接口非常精简:创建线程池,增加任务到线程池,销毁线程池。
| 参数 | 说明 |
|---|---|
| pool | 线程池句柄 |
| name | 线程池中线程名字 |
| stack_size | 线程池中线程的栈大小 |
| thead_num | 线程池中线程数目 |
| 返回 | -- |
| RTP_EINVAL | pool无效参数 |
| RTP_ERROR | 创建失败 |
| RTP_NOMEM | 内存不足 |
| RTP_EOK | 创建成功 |
| 参数 | 说明 |
|---|---|
| pool | 线程池句柄 |
| handle | 线程池中线程名字 |
| argv | 线程池中线程的栈大小 |
| 返回 | -- |
| RTP_EINVAL | pool无效参数 |
| RTP_NOMEM | 内存不足 |
| RTP_EOK | 增加task成功 |
| 参数 | 说明 |
|---|---|
| pool | 线程池句柄 |
| 返回 | -- |
| - | - |
| 参数 | 说明 |
|---|---|
| pool | 线程池句柄 |
| 返回 | -- |
| - | - |
| 参数 | 说明 |
|---|---|
| pool | 线程池句柄 |
| 返回 | -- |
| RTP_EINVAL | pool无效参数 |
| RTP_EOK | 销毁成功 |
| 参数 | 说明 |
|---|---|
| argv | 线程池参数 |
在线程池中创建6个task,其中,task参数为taskId。
#include "RTP.h"
static rtp pool;
void TestRtpHandle(void *argv)
{
printf("%s--taskId: %d\r\n", __FUNCTION__, (uint32_t)argv);
}
int main(void)
{
// ①
rtp_create(&pool, "rtp", 1024, 3);
// ②
rtp_add_task(&pool, TestRtpHandle, (void *)1);
rtp_add_task(&pool, TestRtpHandle, (void *)2);
rtp_add_task(&pool, TestRtpHandle, (void *)3);
rtp_add_task(&pool, TestRtpHandle, (void *)4);
rtp_add_task(&pool, TestRtpHandle, (void *)5);
rtp_add_task(&pool, TestRtpHandle, (void *)6);
return 0;
}