void complete(struct completion *x)用于wakeup 等在completion *x 上的thread
属于完成量使用的标准函数。完成量的用法之前的博文有讲过。
其源码分析如下:
void complete(struct completion *x)
{
unsigned long flags;
spin_lock_irqsave(&x->wait.lock, flags);
if (x->done != UINT_MAX)
x->done++;
__wake_up_locked(&x->wait, TASK_NORMAL, 1);
spin_unlock_irqrestore(&x->wait.lock, flags);
}
这里先判断如果x->done 不等于最大值就累加,然后调用__wake_up_locked 来wakeup等待在x->wait
上的task,注意这里的__wake_up_locked 最后一个函数是1,表示只wakeup 一个函数。
void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr)
{
__wake_up_common(q, mode, nr, 0, NULL);
}
这里的nr 为1
static void __wake_up_common(wait_queue_head_t *q, unsigned int mode,
int nr_exclusive, int wake_flags, void *key)
{
wait_queue_t *curr, *next;
list_for_each_entry_safe(curr, next, &q->task_list, task_list) {
unsigned flags = curr->flags;
#这里的nr_exclusive 为1,因此!--nr_exclusive 等于1,再减去1的话,这个表达式就为0了,
#所以__wake_up_locked 中的nr为1,表示只能wakeup一个task
if (curr->func(curr, mode, wake_flags, key) &&
(flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
break;
}
}
进程调度API之complete
最新推荐文章于 2022-09-20 19:00:00 发布