/* This function will wake up a pending thread on the specified waiting queue that meets the conditions.  */
void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
/* This function will wake up a pending thread on the specified waiting queue that meets the conditions.  */
void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
{
    rt_base_t level;
    int need_schedule = 0;
    rt_list_t *queue_list;
    struct rt_list_node *node;
    struct rt_wqueue_node *entry;
    queue_list = &(queue->waiting_list);
    level = rt_spin_lock_irqsave(&(queue->spinlock));
    queue->flag = RT_WQ_FLAG_WAKEUP;
    if (!(rt_list_isempty(queue_list)))
    {
        for (node = queue_list->next; node != queue_list; node = node->next)
        {
            entry = rt_list_entry(node, struct rt_wqueue_node, list);
            if (entry->wakeup(entry, key) == 0)
            {
                rt_thread_resume(entry->polling_thread);
                need_schedule = 1;
                rt_list_remove(&(entry->list));
                break;
            }
        }
    }
    rt_spin_unlock_irqrestore(&(queue->spinlock), level);
    if (need_schedule)
        rt_schedule();
}