----------等待队列的使用----------
1.DEFINE_WAIT(wait); //定义当前进程的等待队列wait
#define DEFINE_WAIT_FUNC(name, function) \
wait_queue_t name = { \
.private = current, \
.func = function, \ //该函数被调用的情况:被__wake_up_common()调用
.task_list = LIST_HEAD_INIT((name).task_list), \
}
#defineDEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
typedef struct __wait_queue wait_queue_t;
struct__wait_queue{
unsigned intflags; //唤醒方式
#define WQ_FLAG_EXCLUSIVE 0x01
void *private;
wait_queue_func_t func;
struct list_head task_list;
};
//唤醒方式有 WQ_FLAG_EXCLUSIVE 或者 0;
WQ_FLAG_EXCLUSIVE:表示节点对应进程对临界资源使用具有排他性。在唤醒是会唤醒所有非排他性进程和一定数量的排他性进程。见__wake_up_common()函数:
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;
}
}
2. prepare_to_wait(&pgdat->kswapd_wait, &wait,TASK_INTERRUPTIBLE); //将wait挂在等待队列头kswapd_wait上
prepare_to_wait(wait_queue_head_t*q,wait_queue_t*wait, int state)
struct __wait_queue_head {
spinlock_t lock;
struct list_headtask_list;
};
typedef struct __wait_queue_head wait_queue_head_t;
3. schedule_timeout(HZ/10); //调度其他进程
4.finish_wait(&pgdat->kswapd_wait, &wait); //当前进程被调度后,将wait从等待队列上删除
等待队列的使用
最新推荐文章于 2021-05-13 19:30:02 发布