* @brief This function will wake up a pending thread on the specified * waiting queue that meets the conditions. * * @param queue is a pointer to the wait queue. * * @param key is the wakeup conditions, but it is not effective now, because * default wakeup function always return 0. * If user wants to use it, user should define their own wakeup function. */
| 78 | * If user wants to use it, user should define their own wakeup function. |
| 79 | */ |
| 80 | void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key) |
| 81 | { |
| 82 | rt_base_t level; |
| 83 | int need_schedule = 0; |
| 84 | |
| 85 | rt_list_t *queue_list; |
| 86 | struct rt_list_node *node; |
| 87 | struct rt_wqueue_node *entry; |
| 88 | |
| 89 | queue_list = &(queue->waiting_list); |
| 90 | |
| 91 | level = rt_spin_lock_irqsave(&(queue->spinlock)); |
| 92 | /* set wakeup flag in the queue */ |
| 93 | queue->flag = RT_WQ_FLAG_WAKEUP; |
| 94 | |
| 95 | if (!(rt_list_isempty(queue_list))) |
| 96 | { |
| 97 | for (node = queue_list->next; node != queue_list; node = node->next) |
| 98 | { |
| 99 | entry = rt_list_entry(node, struct rt_wqueue_node, list); |
| 100 | if (entry->wakeup(entry, key) == 0) |
| 101 | { |
| 102 | /** |
| 103 | * even though another thread may interrupt the thread and |
| 104 | * wakeup it meanwhile, we can asuume that condition is ready |
| 105 | */ |
| 106 | entry->polling_thread->error = RT_EOK; |
| 107 | if (!rt_thread_resume(entry->polling_thread)) |
| 108 | { |
| 109 | need_schedule = 1; |
| 110 | |
| 111 | rt_list_remove(&(entry->list)); |
| 112 | |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | rt_spin_unlock_irqrestore(&(queue->spinlock), level); |
| 119 | if (need_schedule) |
| 120 | rt_schedule(); |
| 121 | |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @brief This function will wake up all pending thread on the specified |
no test coverage detected