void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
和__wake_up 函数的形参和作用一样。不同在于会根据是如果nr_exclusive等于1的话,传递给
wakup 后要执行函数的wake_flags 等于1.而__wake_up 传递的wake_flags always是0
void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
{
__wake_up_sync_key(q, mode, nr_exclusive, NULL);
}
可以看到__wake_up_sync_key 最后一个参数是null
void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode,
int nr_exclusive, void *key)
{
unsigned long flags;
int wake_flags = 1; /* XXX WF_SYNC */
if (unlikely(!q))
return;
#如果nr_exclusive 等于1的话,这里的wake_flags 就是1
if (unlikely(nr_exclusive != 1))
wake_flags = 0;
spin_lock_irqsave(&q->lock, flags);
#__wake_up 和 __wake_up_sync 最终都会调用__wake_up_common,其区别就在第四个参数,
#__wake_up 调用__wake_up_common的时候wake_flags 这个形参always是0.但是__wake_up_sync
#调用的时候,这个参数大部分情况下是1
__wake_up_common(q, mode, nr_exclusive, wake_flags, key);
spin_unlock_irqrestore(&q->lock, flags);
}
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;
if (curr->func(curr, mode, wake_flags, key) &&
(flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
break;
}
}
最终wake_flags 会传递给用户自己定义的wakeup的callback函数,这个wake_flags的意义就在于
用户可以根据这个是0还是1判断当前thread是否被独占.
进程调度API之__wake_up_sync
最新推荐文章于 2023-02-27 19:39:14 发布