Ejemplo n.º 1
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();
}
Ejemplo n.º 2
0
rt_err_t rt_memheap_detach(struct rt_memheap *heap)
{
    RT_ASSERT(heap);

    rt_object_detach(&(heap->lock.parent.parent));
    rt_object_detach(&(heap->parent));

    /* Return a successful completion. */
    return RT_EOK;
}
Ejemplo n.º 3
0
/**
 * This function will detach a thread. The thread object will be removed from
 * thread queue and detached/deleted from system object management.
 *
 * @param thread the thread to be deleted
 *
 * @return the operation status, RT_EOK on OK, -RT_ERROR on error
 *
 */
rt_err_t rt_thread_detach(rt_thread_t thread)
{
	rt_base_t lock;

	/* thread check */
	RT_ASSERT(thread != RT_NULL);

	/* remove from schedule */
	rt_schedule_remove_thread(thread);

	/* release thread timer */
	rt_timer_detach(&(thread->thread_timer));

	/* change stat */
	thread->stat = RT_THREAD_CLOSE;

	/* detach object */
	rt_object_detach((rt_object_t)thread);

	if (thread->cleanup != RT_NULL)
	{
		/* disable interrupt */
		lock = rt_hw_interrupt_disable();

		/* insert to defunct thread list */
		rt_list_insert_after(&rt_thread_defunct, &(thread->tlist));

		/* enable interrupt */
		rt_hw_interrupt_enable(lock);
	}

	return RT_EOK;
}
Ejemplo n.º 4
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();
}
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
    rt_err_t result;
    char cond_name[RT_NAME_MAX];
    static rt_uint16_t cond_num = 0;

    /* parameter check */
    if (cond == RT_NULL)
        return EINVAL;
    if ((attr != RT_NULL) && (*attr != PTHREAD_PROCESS_PRIVATE))
        return EINVAL;

    rt_snprintf(cond_name, sizeof(cond_name), "cond%02d", cond_num++);

	if (attr == RT_NULL) /* use default value */
		cond->attr = PTHREAD_PROCESS_PRIVATE;
	else 
	    cond->attr = *attr;

    result = rt_sem_init(&cond->sem, cond_name, 0, RT_IPC_FLAG_FIFO);
    if (result != RT_EOK)
        return EINVAL;

    /* detach the object from system object container */
    rt_object_detach(&(cond->sem.parent.parent));

    return 0;
}
Ejemplo n.º 6
0
/**
 * This function removes a previously registered device driver
 *
 * @param dev the pointer of device driver structure
 *
 * @return the error code, RT_EOK on successfully.
 */
rt_err_t rt_device_unregister(rt_device_t dev)
{
    RT_ASSERT(dev != RT_NULL);

    rt_object_detach(&(dev->parent));

    return RT_EOK;
}
Ejemplo n.º 7
0
/**
 * This function will detach a mutex from resource management
 *
 * @param mutex the mutex object
 *
 * @return the operation status, RT_EOK on successful
 *
 * @see rt_mutex_delete
 */
rt_err_t rt_mutex_detach (rt_mutex_t mutex)
{
	RT_ASSERT(mutex != RT_NULL);

	/* wakeup all suspend threads */
	rt_ipc_object_resume_all(&(mutex->parent));

	/* detach semaphore object */
	rt_object_detach(&(mutex->parent.parent));

	return RT_EOK;
}
Ejemplo n.º 8
0
/**
 * This function will detach a semaphore from resource management
 *
 * @param sem the semaphore object
 *
 * @return the operation status, RT_EOK on successful
 *
 * @see rt_sem_delete
 */
rt_err_t rt_sem_detach (rt_sem_t sem)
{
	RT_ASSERT(sem != RT_NULL);

	/* wakeup all suspend threads */
	rt_ipc_object_resume_all(&(sem->parent));

	/* detach semaphore object */
	rt_object_detach(&(sem->parent.parent));

	return RT_EOK;
}
Ejemplo n.º 9
0
/**
 * This task will delete the rms task
 */
rt_err_t rt_rms_delete(rt_rms_t rms)
{

    RT_ASSERT(rms != RT_NULL);

    rt_timer_detach(&rms->thread->thread_timer);
    rt_timer_detach(&rms->rms_timer);

    rms->thread->stat = RT_RMS_CLOSE;
    rt_object_detach((rt_object_t)rms->thread);
    rt_list_remove(&(rms->thread->tlist));
    rt_list_remove(&(rms->rlist));

    return RT_RMS_EOK;
}
Ejemplo n.º 10
0
/**
 * This function will detach a timer from timer management.
 *
 * @param timer the static timer object
 *
 * @return the operation status, RT_EOK on OK; RT_ERROR on error
 */
rt_err_t rt_timer_detach(rt_timer_t timer)
{
    register rt_base_t level;

    /* timer check */
    RT_ASSERT(timer != RT_NULL);

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

    _rt_timer_remove(timer);

    /* enable interrupt */
    rt_hw_interrupt_enable(level);

    rt_object_detach((rt_object_t)timer);

    return -RT_EOK;
}
Ejemplo n.º 11
0
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
{
	rt_err_t result;
	char name[RT_NAME_MAX];
	static rt_uint16_t pthread_mutex_number = 0;

	if (!mutex) return EINVAL;

	/* build mutex name */
	rt_snprintf(name, sizeof(name), "pmtx%02d", pthread_mutex_number ++);
	if (attr == RT_NULL) mutex->attr = pthread_default_mutexattr;
	else mutex->attr = *attr;

	/* init mutex lock */
	result = rt_mutex_init(&(mutex->lock), name, RT_IPC_FLAG_FIFO);
	if (result != RT_EOK) return EINVAL;

	/* detach the object from system object container */
	rt_object_detach(&(mutex->lock.parent.parent));

	return 0;
}
Ejemplo n.º 12
0
/**
 * This function will detach a memory pool from system object management.
 *
 * @param mp the memory pool object
 *
 * @return RT_EOK
 */
rt_err_t rt_mp_detach(struct rt_mempool *mp)
{
	struct rt_thread *thread;
	register rt_ubase_t temp;

	/* parameter check */
	RT_ASSERT(mp != RT_NULL);

	/* wake up all suspended threads */
	while (!rt_list_isempty(&(mp->suspend_thread)))
	{
		/* disable interrupt */
		temp = rt_hw_interrupt_disable();

		/* get next suspend thread */
		thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist);
		/* set error code to RT_ERROR */
		thread->error = -RT_ERROR;

		/*
		 * resume thread
		 * In rt_thread_resume function, it will remove current thread from suspend
		 * list
		 */
		rt_thread_resume(thread);

		/* decrease suspended thread count */
		mp->suspend_thread_count --;

		/* enable interrupt */
		rt_hw_interrupt_enable(temp);
	}

	/* detach object */
	rt_object_detach(&(mp->parent));

	return RT_EOK;
}