等待队列

来源:互联网 发布:淘宝虚假交易新规则 编辑:程序博客网 时间:2024/05/17 03:01

在阻塞IO操作中,用于实现阻塞进程的唤醒和阻塞,其常常与进程的调度函数混合使用。当将当前进程加入等待队列链表后通常使用__set_current_state(TASK_INTERRUPTIBLE)和schedule()将进程睡眠,资源可使用后,释放资源的进程通过wake_up_interruptible唤醒需要资源的已睡眠进程,再将该进程的等待队列删除。
struct __wait_queue {
 unsigned int flags; //互斥或非互斥
 #define WQ_FLAG_EXCLUSIVE 0x01
 void *private; //当前进程
 wait_queue_func_t func;//唤醒柱塞任务的函数
 struct list_head task_list;//阻塞任务链表,用于链接
};

struct __wait_queue_head {
 spinlock_t lock;//之选锁,用于添加和删除等待链表时只有一个操作者
 struct list_head task_list;//等待队列链表
};

原创粉丝点击