Example #1
0
void rt_rms_exit(void)
{
    struct rt_rms *rms;
    register rt_base_t level;

    /* get current rms */
    rms = rt_current_rms;

    /* disable interrupt */
    level = rt_hw_interrupt_disable();

    /* remove from schedule */
    rt_schedule_remove_rms(rms);
    /* change stat */
    rms->thread->stat = RT_RMS_CLOSE;

    /* remove it from timer list */
    rt_timer_detach(&rms->rms_timer);
    rt_timer_detach(&rms->thread->thread_timer);
    if(rt_object_is_systemobject((rt_object_t)rms->thread) == RT_TRUE)
    {
        rt_object_detach((rt_object_t)rms->thread);
    }
    rt_list_remove(&(rms->thread->tlist));
    rt_list_remove(&(rms->rlist));
    /* enable interrupt */
    rt_hw_interrupt_enable(level);

    /* switch to next task */
    rt_schedule();
}
Example #2
0
static void rt_thread_exit(void)
{
	struct rt_thread *thread;
	register rt_base_t level;

	/* get current thread */
	thread = rt_current_thread;

	/* disable interrupt */
	level = rt_hw_interrupt_disable();

	/* remove from schedule */
	rt_schedule_remove_thread(thread);
	/* change stat */
	thread->stat = RT_THREAD_CLOSE;

	/* remove it from timer list */
	rt_list_remove(&(thread->thread_timer.list));
	rt_object_detach((rt_object_t)&(thread->thread_timer));

	if ((rt_object_is_systemobject((rt_object_t)thread) == RT_EOK) &&
		thread->cleanup == RT_NULL) {
		rt_object_detach((rt_object_t)thread);
	} else {
		/* insert to defunct thread list */
		rt_list_insert_after(&rt_thread_defunct, &(thread->tlist));
	}

	/* enable interrupt */
	rt_hw_interrupt_enable(level);

	/* switch to next task */
	rt_schedule();
}
Example #3
0
/**
 * @ingroup Thread
 *
 * This function will perform system background job when system idle.
 */
void rt_thread_idle_excute(void)
{
    /* check the defunct thread list */
    if (!rt_list_isempty(&rt_thread_defunct))
    {
        rt_base_t lock;
        rt_thread_t thread;
#ifdef RT_USING_MODULE
        rt_module_t module = RT_NULL;
#endif
        RT_DEBUG_NOT_IN_INTERRUPT;

        /* disable interrupt */
        lock = rt_hw_interrupt_disable();

        /* re-check whether list is empty */
        if (!rt_list_isempty(&rt_thread_defunct))
        {
            /* get defunct thread */
            thread = rt_list_entry(rt_thread_defunct.next,
                                   struct rt_thread,
                                   tlist);
#ifdef RT_USING_MODULE
            /* get thread's parent module */
            module = (rt_module_t)thread->module_id;

            /* if the thread is module's main thread */
            if (module != RT_NULL && module->module_thread == thread)
            {
                /* detach module's main thread */
                module->module_thread = RT_NULL;
            }
#endif
            /* remove defunct thread */
            rt_list_remove(&(thread->tlist));
            /* invoke thread cleanup */
            if (thread->cleanup != RT_NULL)
                thread->cleanup(thread);

            /* if it's a system object, not delete it */
            if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
            {
                /* enable interrupt */
                rt_hw_interrupt_enable(lock);

                return;
            }
        }