我正在使用 tm4c1294+lwip1.4.1+FreeRTOS。
正如netconn_alloc()
所要求的socket communication
,它分配一个未使用的信号量。信号量的个数定义为SYS_SEM_MAX,所以不能超过SYS_SEM_MAX
。但是,由于信号量是连续分配的,它会到达SYS_SEM_MAX
并停止工作,因为我猜sys_sem_free()
它没有正确释放它
这是创建在 sys_arch.c 中实现的信号量的函数
err_t
sys_sem_new(sys_sem_t *sem, u8_t count)
{
void *temp;
u32_t i;
/* Find a semaphore that is not in use. */
for(i = 0; i < SYS_SEM_MAX; i++) {
if(sems[i].queue == 0) {
break;
}
}
if(i == SYS_SEM_MAX) {
#if SYS_STATS
STATS_INC(sys.sem.err);
#endif /* SYS_STATS */
return ERR_MEM;
}
/* Create a single-entry queue to act as a semaphore. */
#if RTOS_FREERTOS
sem->queue = xQueueCreate(1, sizeof(void *));
if(sem->queue == NULL) {
#endif /* RTOS_FREERTOS */
#if SYS_STATS
STATS_INC(sys.sem.err);
#endif /* SYS_STATS */
return ERR_MEM;
}
/* Acquired the semaphore if necessary. */
if(count == 0) {
temp = 0;
xQueueSend(sem->queue, &temp, 0);
}
/* Update the semaphore statistics. */
#if SYS_STATS
STATS_INC(sys.sem.used);
#if LWIP_STATS
if(lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
}
#endif
#endif /* SYS_STATS */
/* Save the queue handle. */
sems[i].queue = sem->queue;
/* Return this semaphore. */
return (ERR_OK);
}
这是另一个释放 sys_arch.c 中实现的信号量的函数
void
sys_sem_free(sys_sem_t *sem)
{
/* Delete Sem , By Jin */
vQueueDelete(sem->queue);
/* Clear the queue handle. */
sem->queue = 0;
/* Update the semaphore statistics. */
#if SYS_STATS
STATS_DEC(sys.sem.used);
#endif /* SYS_STATS */
}
每当netconn_free()
被调用时会sys_sem_free()
释放信号量,但不会释放在 中分配的信号量sem[] array
。
我补充vQueueDelete(sem->queue);
说这是有人建议的,但仍然一样。
不仅函数创建/释放semaphore
,而且函数处理mbox
与上述函数相同,因此函数处理mbox
也可能是错误的。
有人已经向 TI 报告了这个问题,但他们似乎还没有解决问题。
因此,我可能需要实现我自己的函数处理semaphore/mbox
,sys_arch.c
但到目前为止我没有任何线索。
谁能给我任何想法?还是什么?
谢谢,晋