/* This function will suspend a thread to a specified list. IPC object or some double-queue object (mailbox etc.) contains this kind of list. */
rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, struct rt_thread *thread, rt_uint8_t flag)
/* This function will suspend a thread to a specified list. IPC object or some double-queue object (mailbox etc.) contains this kind of list. */
rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, struct rt_thread *thread, rt_uint8_t flag)
{
    rt_thread_suspend(thread);
    switch (flag)
    {
    case RT_IPC_FLAG_FIFO:
        rt_list_insert_before(list, &(thread->tlist));
        break;
    case RT_IPC_FLAG_PRIO:
        {
            struct rt_list_node *n;
            struct rt_thread *sthread;
            for (n = list->next; n != list; n = n->next)
            {
                sthread = rt_list_entry(n, struct rt_thread, tlist);
                if (thread->current_priority < sthread->current_priority)
                {
                    rt_list_insert_before(&(sthread->tlist), &(thread->tlist));
                    break;
                }
            }
            if (n == list)
                rt_list_insert_before(list, &(thread->tlist));
        }
        break;
    }
    return RT_EOK;
}