修正rt_mp_free有可能唤醒一个错误任务指针的问题
This commit is contained in:
parent
91c858ead2
commit
ae1fdc70f0
|
@ -675,6 +675,8 @@ long list_mempool(void)
|
||||||
{
|
{
|
||||||
struct rt_object *obj;
|
struct rt_object *obj;
|
||||||
struct rt_mempool *mp;
|
struct rt_mempool *mp;
|
||||||
|
int suspend_thread_count;
|
||||||
|
rt_list_t *node;
|
||||||
|
|
||||||
obj = rt_list_entry(obj_list[i], struct rt_object, list);
|
obj = rt_list_entry(obj_list[i], struct rt_object, list);
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
@ -687,7 +689,14 @@ long list_mempool(void)
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
mp = (struct rt_mempool *)obj;
|
mp = (struct rt_mempool *)obj;
|
||||||
if (mp->suspend_thread_count > 0)
|
|
||||||
|
suspend_thread_count = 0;
|
||||||
|
for (node = mp->suspend_thread.next; node != &mp->suspend_thread; node = node->next)
|
||||||
|
{
|
||||||
|
suspend_thread_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suspend_thread_count > 0)
|
||||||
{
|
{
|
||||||
rt_kprintf("%-*.*s %04d %04d %04d %d:",
|
rt_kprintf("%-*.*s %04d %04d %04d %d:",
|
||||||
maxlen, RT_NAME_MAX,
|
maxlen, RT_NAME_MAX,
|
||||||
|
@ -695,7 +704,7 @@ long list_mempool(void)
|
||||||
mp->block_size,
|
mp->block_size,
|
||||||
mp->block_total_count,
|
mp->block_total_count,
|
||||||
mp->block_free_count,
|
mp->block_free_count,
|
||||||
mp->suspend_thread_count);
|
suspend_thread_count);
|
||||||
show_wait_queue(&(mp->suspend_thread));
|
show_wait_queue(&(mp->suspend_thread));
|
||||||
rt_kprintf("\n");
|
rt_kprintf("\n");
|
||||||
}
|
}
|
||||||
|
@ -707,7 +716,7 @@ long list_mempool(void)
|
||||||
mp->block_size,
|
mp->block_size,
|
||||||
mp->block_total_count,
|
mp->block_total_count,
|
||||||
mp->block_free_count,
|
mp->block_free_count,
|
||||||
mp->suspend_thread_count);
|
suspend_thread_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -815,7 +815,6 @@ struct rt_mempool
|
||||||
rt_size_t block_free_count; /**< numbers of free memory block */
|
rt_size_t block_free_count; /**< numbers of free memory block */
|
||||||
|
|
||||||
rt_list_t suspend_thread; /**< threads pended on this resource */
|
rt_list_t suspend_thread; /**< threads pended on this resource */
|
||||||
rt_size_t suspend_thread_count; /**< numbers of thread pended on this resource */
|
|
||||||
};
|
};
|
||||||
typedef struct rt_mempool *rt_mp_t;
|
typedef struct rt_mempool *rt_mp_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -103,7 +103,6 @@ rt_err_t rt_mp_init(struct rt_mempool *mp,
|
||||||
|
|
||||||
/* initialize suspended thread list */
|
/* initialize suspended thread list */
|
||||||
rt_list_init(&(mp->suspend_thread));
|
rt_list_init(&(mp->suspend_thread));
|
||||||
mp->suspend_thread_count = 0;
|
|
||||||
|
|
||||||
/* initialize free block list */
|
/* initialize free block list */
|
||||||
block_ptr = (rt_uint8_t *)mp->start_address;
|
block_ptr = (rt_uint8_t *)mp->start_address;
|
||||||
|
@ -157,9 +156,6 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp)
|
||||||
*/
|
*/
|
||||||
rt_thread_resume(thread);
|
rt_thread_resume(thread);
|
||||||
|
|
||||||
/* decrease suspended thread count */
|
|
||||||
mp->suspend_thread_count --;
|
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(temp);
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
@ -219,7 +215,6 @@ rt_mp_t rt_mp_create(const char *name,
|
||||||
|
|
||||||
/* initialize suspended thread list */
|
/* initialize suspended thread list */
|
||||||
rt_list_init(&(mp->suspend_thread));
|
rt_list_init(&(mp->suspend_thread));
|
||||||
mp->suspend_thread_count = 0;
|
|
||||||
|
|
||||||
/* initialize free block list */
|
/* initialize free block list */
|
||||||
block_ptr = (rt_uint8_t *)mp->start_address;
|
block_ptr = (rt_uint8_t *)mp->start_address;
|
||||||
|
@ -275,9 +270,6 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
|
||||||
*/
|
*/
|
||||||
rt_thread_resume(thread);
|
rt_thread_resume(thread);
|
||||||
|
|
||||||
/* decrease suspended thread count */
|
|
||||||
mp->suspend_thread_count --;
|
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(temp);
|
rt_hw_interrupt_enable(temp);
|
||||||
}
|
}
|
||||||
|
@ -334,7 +326,6 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
|
||||||
/* need suspend thread */
|
/* need suspend thread */
|
||||||
rt_thread_suspend(thread);
|
rt_thread_suspend(thread);
|
||||||
rt_list_insert_after(&(mp->suspend_thread), &(thread->tlist));
|
rt_list_insert_after(&(mp->suspend_thread), &(thread->tlist));
|
||||||
mp->suspend_thread_count++;
|
|
||||||
|
|
||||||
if (time > 0)
|
if (time > 0)
|
||||||
{
|
{
|
||||||
|
@ -418,7 +409,7 @@ void rt_mp_free(void *block)
|
||||||
*block_ptr = mp->block_list;
|
*block_ptr = mp->block_list;
|
||||||
mp->block_list = (rt_uint8_t *)block_ptr;
|
mp->block_list = (rt_uint8_t *)block_ptr;
|
||||||
|
|
||||||
if (mp->suspend_thread_count > 0)
|
if (!rt_list_isempty(&(mp->suspend_thread)))
|
||||||
{
|
{
|
||||||
/* get the suspended thread */
|
/* get the suspended thread */
|
||||||
thread = rt_list_entry(mp->suspend_thread.next,
|
thread = rt_list_entry(mp->suspend_thread.next,
|
||||||
|
@ -431,9 +422,6 @@ void rt_mp_free(void *block)
|
||||||
/* resume thread */
|
/* resume thread */
|
||||||
rt_thread_resume(thread);
|
rt_thread_resume(thread);
|
||||||
|
|
||||||
/* decrease suspended thread count */
|
|
||||||
mp->suspend_thread_count --;
|
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue