[kernel] rearrange rt_thread_control() - schedule the thread when close it
This commit is contained in:
parent
c21f018b4a
commit
2b98ac215a
|
@ -14,18 +14,10 @@ void __rt_libc_exit(int status)
|
||||||
{
|
{
|
||||||
rt_thread_t self = rt_thread_self();
|
rt_thread_t self = rt_thread_self();
|
||||||
|
|
||||||
#ifdef RT_USING_MODULE
|
|
||||||
if (dlmodule_self())
|
|
||||||
{
|
|
||||||
dlmodule_exit(status);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (self != RT_NULL)
|
if (self != RT_NULL)
|
||||||
{
|
{
|
||||||
rt_kprintf("thread:%s exit:%d!\n", self->name, status);
|
rt_kprintf("thread:%s exit:%d!\n", self->name, status);
|
||||||
rt_thread_suspend(self);
|
rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
|
||||||
rt_schedule();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
src/thread.c
15
src/thread.c
|
@ -26,6 +26,7 @@
|
||||||
* bug when thread has not startup.
|
* bug when thread has not startup.
|
||||||
* 2018-11-22 Jesven yield is same to rt_schedule
|
* 2018-11-22 Jesven yield is same to rt_schedule
|
||||||
* add support for tasks bound to cpu
|
* add support for tasks bound to cpu
|
||||||
|
* 2021-02-24 Meco Man rearrange rt_thread_control() - schedule the thread when close it
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
|
@ -671,6 +672,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RT_THREAD_CTRL_CHANGE_PRIORITY:
|
case RT_THREAD_CTRL_CHANGE_PRIORITY:
|
||||||
|
{
|
||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
temp = rt_hw_interrupt_disable();
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
|
@ -712,22 +714,30 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(temp);
|
rt_hw_interrupt_enable(temp);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case RT_THREAD_CTRL_STARTUP:
|
case RT_THREAD_CTRL_STARTUP:
|
||||||
|
{
|
||||||
return rt_thread_startup(thread);
|
return rt_thread_startup(thread);
|
||||||
|
}
|
||||||
|
|
||||||
case RT_THREAD_CTRL_CLOSE:
|
case RT_THREAD_CTRL_CLOSE:
|
||||||
|
{
|
||||||
|
rt_err_t rt_err;
|
||||||
|
|
||||||
if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
|
if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
|
||||||
{
|
{
|
||||||
return rt_thread_detach(thread);
|
rt_err = rt_thread_detach(thread);
|
||||||
}
|
}
|
||||||
#ifdef RT_USING_HEAP
|
#ifdef RT_USING_HEAP
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return rt_thread_delete(thread);
|
rt_err = rt_thread_delete(thread);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
rt_schedule();
|
||||||
|
return rt_err;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_SMP
|
#ifdef RT_USING_SMP
|
||||||
case RT_THREAD_CTRL_BIND_CPU:
|
case RT_THREAD_CTRL_BIND_CPU:
|
||||||
|
@ -745,6 +755,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /*RT_USING_SMP*/
|
#endif /*RT_USING_SMP*/
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue